<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>python wiki</title>
<link>http://pythonwiki.tiddlyspot.com</link>
<description>notes on learning the language</description>
<language>en-us</language>
<copyright>Copyright 2013 WarpCat</copyright>
<pubDate>Fri, 17 May 2013 20:36:43 GMT</pubDate>
<lastBuildDate>Fri, 17 May 2013 20:36:43 GMT</lastBuildDate>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<generator>TiddlyWiki 2.4.0</generator>
<item>
<title>How can I inspect/print pickle data?</title>
<description>I thought it'd be cool to have some sort of &quot;pickle inspector&quot; window, where you could see the contents of saved pickle data.  The below module is the result:  You can drag&amp;amp;drop the pickle file onto this module's icon, and it'll print out the pickled data.  That being said, it's pretty easy to break:  If the pickled data requires any imports from modules that aren't part of your default Python path, it will fail.  But I thought it was a good place to start.&lt;br&gt;&lt;pre&gt;# pickleInspector.py
import sys
import pickle
from pprint import pprint

def main(args):
    &quot;&quot;&quot;
    Print the values from the pickled data.
    &quot;&quot;&quot;
    if len(args) != 2:
        return
    with open(args[1]) as gerken:
        loadedData = pickle.load(gerken)
    pprint(loadedData)

if __name__ == &quot;__main__&quot;:
    try:
        main(sys.argv)
    except Exception, e:
        print &quot;EXCEPTION&quot;, e
    finally:
        raw_input(&quot;Press Enter to exit...&quot;)
&lt;/pre&gt;</description>
<category>FILESYSTEMS</category>
<category>pickle</category>
<category>inspect</category>
<category>print</category>
<category>pprint</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BHow%20can%20I%20inspect%2Fprint%20pickle%20data%3F%5D%5D</link>
<pubDate>Fri, 17 May 2013 20:36:38 GMT</pubDate>
</item>
<item>
<title>Plant algorithms</title>
<description>Not Python related persay, but nice selection of papers here:&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://algorithmicbotany.org/papers/&quot; title=&quot;External link to http://algorithmicbotany.org/papers/&quot; target=&quot;_blank&quot;&gt;http://algorithmicbotany.org/papers/&lt;/a&gt;</description>
<category>MATH</category>
<category>plant</category>
<category>algorithm</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BPlant%20algorithms%5D%5D</link>
<pubDate>Fri, 17 May 2013 17:26:00 GMT</pubDate>
</item>
<item>
<title>How can I make sounds in Python?</title>
<description>On Windows, it's pretty easy to make some nice beeping sounds with &lt;code&gt;winsound.Beep&lt;/code&gt;:&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://docs.python.org/library/winsound.html&quot; title=&quot;External link to http://docs.python.org/library/winsound.html&quot; target=&quot;_blank&quot;&gt;http://docs.python.org/library/winsound.html&lt;/a&gt;&lt;br&gt;&lt;pre&gt;import winsound
for i in range(50, 5000, 10):
    winsound.Beep(i, 25)
&lt;/pre&gt;&lt;hr&gt;Blog post dealing with &lt;a class=&quot;externalLink&quot; href=&quot;http://people.csail.mit.edu/hubert/pyaudio/&quot; title=&quot;External link to http://people.csail.mit.edu/hubert/pyaudio/&quot; target=&quot;_blank&quot;&gt;PyAudio&lt;/a&gt;:&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://davywybiral.blogspot.com/2010/09/procedural-music-with-pyaudio-and-numpy.html&quot; title=&quot;External link to http://davywybiral.blogspot.com/2010/09/procedural-music-with-pyaudio-and-numpy.html&quot; target=&quot;_blank&quot;&gt;http://davywybiral.blogspot.com/2010/09/procedural-music-with-pyaudio-and-numpy.html&lt;/a&gt;&lt;br&gt;&lt;hr&gt;Blog post about other Python implementations:&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://diagrammes-modernes.blogspot.com/2007/08/music-control-tools-python-based.html&quot; title=&quot;External link to http://diagrammes-modernes.blogspot.com/2007/08/music-control-tools-python-based.html&quot; target=&quot;_blank&quot;&gt;http://diagrammes-modernes.blogspot.com/2007/08/music-control-tools-python-based.html&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;a class=&quot;externalLink&quot; href=&quot;https://github.com/kroger/pyknon&quot; title=&quot;External link to https://github.com/kroger/pyknon&quot; target=&quot;_blank&quot;&gt;Pyknon&lt;/a&gt;&lt;br&gt;&quot;Pyknon is a simple music library for Python hackers. With Pyknon you can generate Midi files quickly and reason about musical&lt;br&gt;proprieties.&quot;&lt;br&gt;&lt;hr&gt;There's also the builtin &lt;a class=&quot;externalLink&quot; href=&quot;http://docs.python.org/2/library/wave.html&quot; title=&quot;External link to http://docs.python.org/2/library/wave.html&quot; target=&quot;_blank&quot;&gt;wave&lt;/a&gt; library that can read and write wav data, but I'm not sure if it can actually play it.</description>
<category>MEDIA</category>
<category>audio</category>
<category>sound</category>
<category>winsound</category>
<category>winsound.Beep</category>
<category>pyaudio</category>
<category>music</category>
<category>pyknon</category>
<category>wave</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BHow%20can%20I%20make%20sounds%20in%20Python%3F%5D%5D</link>
<pubDate>Fri, 17 May 2013 16:27:00 GMT</pubDate>
</item>
<item>
<title>How can I play a wav file?</title>
<description>On Windows:&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://docs.python.org/library/winsound.html&quot; title=&quot;External link to http://docs.python.org/library/winsound.html&quot; target=&quot;_blank&quot;&gt;http://docs.python.org/library/winsound.html&lt;/a&gt;&lt;br&gt;&lt;pre&gt;import winsound
winsound.PlaySound('c:/temp/myWav.wav', winsound.SND_ALIAS)
&lt;/pre&gt;&lt;hr&gt;There's also the builtin &lt;a class=&quot;externalLink&quot; href=&quot;http://docs.python.org/2/library/wave.html&quot; title=&quot;External link to http://docs.python.org/2/library/wave.html&quot; target=&quot;_blank&quot;&gt;wave&lt;/a&gt; library that can read and write wav data, but I'm not sure if it can actually play it.</description>
<category>MEDIA</category>
<category>audio</category>
<category>sound</category>
<category>wav</category>
<category>winsound</category>
<category>winsound.PlaySound</category>
<category>wave</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BHow%20can%20I%20play%20a%20wav%20file%3F%5D%5D</link>
<pubDate>Fri, 17 May 2013 16:27:00 GMT</pubDate>
</item>
<item>
<title>How can I kill/close a window by name?</title>
<description>It's easy to make a &lt;code&gt;Tkinter&lt;/code&gt; window, but I was often stumped on how to close them, if one is already open.  Meaning:  A window is open, the user re-clicks on the icon to create it:  now there are two windows.  Instead, I want the first one deleted, before the second one is created.&lt;br&gt;&lt;br&gt;The below code will delete any application if it can match the given 'title' string in the data that the dos &lt;code&gt;tasklist&lt;/code&gt; returns.  Windows only, obviously.  The idea is, before the window is created, this code is first ran to see if there is a pre-existing one, and if so, it kills it.&lt;br&gt;&lt;pre&gt;import subprocess
def killWindow(title):
    &quot;&quot;&quot;
    Windows only:  Uses the tasklist &amp;amp; taskkill dos cmds.
    Kill the window with the given title.
    &quot;&quot;&quot;
    output = subprocess.Popen(['tasklist', '/FO', 'TABLE', '/V', '/FI', 'IMAGENAME eq python*'],
                                stdout=subprocess.PIPE).stdout
    for line in output:
        strip = line.strip()
        if title in strip:
            # PID is the 2nd item in the list:
            pid = strip.split()[1]
            subprocess.Popen(['taskkill', '/PID', pid])
&lt;/pre&gt;&lt;pre&gt;title = &quot;My Tkinter Window&quot;
killWindow(title)
&lt;/pre&gt;</description>
<category>FILESYSTEMS</category>
<category>Tkinter</category>
<category>window</category>
<category>application</category>
<category>close</category>
<category>kill</category>
<category>subprocess</category>
<category>subprocess.popen</category>
<category>taskkill</category>
<category>tasklist</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BHow%20can%20I%20kill%2Fclose%20a%20window%20by%20name%3F%5D%5D</link>
<pubDate>Mon, 13 May 2013 22:28:00 GMT</pubDate>
</item>
<item>
<title>How can I get a list of all running applications?</title>
<description>On &lt;strong&gt;Windows&lt;/strong&gt;, you can easily acces this via the &lt;code&gt;tasklist&lt;/code&gt; system command:&lt;br&gt;&lt;pre&gt;import subprocess
output = subprocess.Popen(['tasklist'], stdout=subprocess.PIPE).stdout
for line in output:
    print line.strip()
&lt;/pre&gt;&lt;pre&gt;Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
System Idle Process              0 Services                   0         24 K
System                           4 Services                   0     38,204 K
smss.exe                       312 Services                   0      1,356 K
csrss.exe                      412 Services                   0      6,076 K
etc...
&lt;/pre&gt;You can also filter the result by passing args to the &lt;code&gt;tasklist&lt;/code&gt; command:&lt;br&gt;&lt;pre&gt;import subprocess
output = subprocess.Popen(['tasklist', '/FI', 'IMAGENAME eq svcHost.exe'], stdout=subprocess.PIPE).stdout
for line in output:
    print line.strip()
&lt;/pre&gt;&lt;pre&gt;Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
svchost.exe                    692 Services                   0     12,284 K
svchost.exe                    840 Services                   0     13,968 K
svchost.exe                    940 Services                   0     20,796 K
etc...
&lt;/pre&gt;Here's a more robust solution that turns all this data into a list of Python dicts, with each dict representing a specific process:&lt;br&gt;&lt;pre&gt;import subprocess
def getTaskData(searchStr=None):
    &quot;&quot;&quot;
    Windows only:  Uses the tasklist dos cmd.
    Based on all running processes, returns a list of dicts: Each dict has these keys:
    &quot;Image Name&quot;, &quot;PID&quot;, &quot;Session Name&quot;, &quot;Session#&quot;, &quot;Mem Usage&quot;, &quot;Status&quot;,
    &quot;User Name&quot;, &quot;CPU Time&quot;, &quot;Window Title&quot;.

    Optionally the user can pass in a search string, which will be used as a filter
    on the &quot;Image Name&quot; (executable name).
    &quot;&quot;&quot;
    output = None
    if searchStr:
        output = subprocess.Popen(['tasklist', '/FO', 'LIST', '/V', '/FI', 'IMAGENAME eq python*'],
                                  stdout=subprocess.PIPE).stdout
    else:
        output = subprocess.Popen(['tasklist', '/FO', 'LIST'],
                                  stdout=subprocess.PIPE).stdout
    data = []
    appender = {}
    for line in output:
        stripped = line.strip()
        if len(stripped) == 0 and len(appender):
            data.append(appender)
            appender = {}
            continue
        kv = [item.strip() for item in line.split(&quot;: &quot;)]
        if kv &amp;gt; 2:
            # Some of our 'values' have the &quot;: &quot; string in them, so we need to
            # rebuild that data after being split:
            k = kv.pop(0)
            v = ': '.join(kv)
            kv = [k,v]
        if kv[1] != '':
            appender[kv[0]] = kv[1]
    if not len(data):
        data.append(appender)

    return data
&lt;/pre&gt;&lt;hr&gt;If you're looking for a way more directly authored in Python, check out this blog post:&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://www.blog.pythonlibrary.org/2010/10/03/how-to-find-and-list-all-running-processes-with-python/&quot; title=&quot;External link to http://www.blog.pythonlibrary.org/2010/10/03/how-to-find-and-list-all-running-processes-with-python/&quot; target=&quot;_blank&quot;&gt;http://www.blog.pythonlibrary.org/2010/10/03/how-to-find-and-list-all-running-processes-with-python/&lt;/a&gt;&lt;br&gt;</description>
<category>FILESYSTEMS</category>
<category>tasklist</category>
<category>process</category>
<category>application</category>
<category>window</category>
<category>subprocess</category>
<category>subprocess.Popen</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BHow%20can%20I%20get%20a%20list%20of%20all%20running%20applications%3F%5D%5D</link>
<pubDate>Mon, 13 May 2013 20:48:00 GMT</pubDate>
</item>
<item>
<title>How can I sort a list of files based on modification date?</title>
<description>You can create a custom sorter function that compares the modification date of the passed in list of files:&lt;br&gt;&lt;pre&gt;import os
import glob

def sortByDate(a,b):
    &quot;&quot;&quot;
    Custom sort function designed to sort a list of files based on their
    modification date.
    &quot;&quot;&quot;
    aTime = os.path.getmtime(a)
    bTime = os.path.getmtime(b)
    if aTime &amp;lt; bTime:
        return -1
    elif aTime == bTime:
        return 0
    elif aTime &amp;gt; bTime:
        return 1

files = glob.glob(&quot;c:/temp/*.txt&quot;)
dateSortedFiles = sorted(files, cmp=sortByDate)
&lt;/pre&gt;</description>
<category>FILESYSTEMS</category>
<category>sort</category>
<category>date</category>
<category>modification</category>
<category>file</category>
<category>os</category>
<category>os.path</category>
<category>os.path.getmtime</category>
<category>glob</category>
<category>glob.glob</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BHow%20can%20I%20sort%20a%20list%20of%20files%20based%20on%20modification%20date%3F%5D%5D</link>
<pubDate>Tue, 07 May 2013 18:46:00 GMT</pubDate>
</item>
<item>
<title>How can I get a previous revision of a file from Perforce?</title>
<description>In the below example, we get a string representing the previous version of a given depot file from Perforce.&lt;br&gt;&lt;br&gt;An interesting thing to note:  &lt;code&gt;p4.run('print')&lt;/code&gt; executes &lt;em&gt;much faster&lt;/em&gt; than &lt;code&gt;p4.run_print()&lt;/code&gt;.  &lt;br&gt;&lt;pre&gt;from P4 import P4

p4 = P4()
p4.connect()

depotFile = &quot;//myDepot/path/to/my/file.txt&quot;
depotInfo = p4.run(&quot;fstat&quot;, depotFile)
headRev = int(depotInfo[0][&quot;headRev&quot;])
prevRev = headRev-1
oldRevData = p4.run('print', &quot;-q&quot;, ['%s#%s'%(depotFile,prevRev)])
oldRevStr = oldRevData[1]
&lt;/pre&gt;</description>
<category>P4</category>
<category>perforce</category>
<category>previous revision</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BHow%20can%20I%20get%20a%20previous%20revision%20of%20a%20file%20from%20Perforce%3F%5D%5D</link>
<pubDate>Mon, 06 May 2013 20:54:00 GMT</pubDate>
</item>
<item>
<title>Perforce access via Python</title>
<description>&lt;a class=&quot;externalLink&quot; href=&quot;http://www.perforce.com/&quot; title=&quot;External link to http://www.perforce.com/&quot; target=&quot;_blank&quot;&gt;http://www.perforce.com/&lt;/a&gt;&lt;br&gt;Perforce is version control software that I use in games development.  Having my animation package Maya (which supports Python scripting) interface with it is really handy.  What resources exist to let Python talk to it?	&lt;br&gt;&lt;hr&gt;They release their installers by version, by os:&lt;br&gt;Windows Installer (Python 2.5):&lt;br&gt;&lt;ul&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;ftp://ftp.perforce.com/perforce/r07.3/bin.ntx86/p4python25.exe&quot; title=&quot;External link to ftp://ftp.perforce.com/perforce/r07.3/bin.ntx86/p4python25.exe&quot; target=&quot;_blank&quot;&gt;ftp://ftp.perforce.com/perforce/r07.3/bin.ntx86/p4python25.exe&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;Source:&lt;br&gt;&lt;ul&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;ftp://ftp.perforce.com/perforce/r07.3/tools/p4python.tgz&quot; title=&quot;External link to ftp://ftp.perforce.com/perforce/r07.3/tools/p4python.tgz&quot; target=&quot;_blank&quot;&gt;ftp://ftp.perforce.com/perforce/r07.3/tools/p4python.tgz&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;Here's the root installer download page, to grab the latest version:&lt;br&gt;&lt;ul&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;ftp://ftp.perforce.com/perforce/&quot; title=&quot;External link to ftp://ftp.perforce.com/perforce/&quot; target=&quot;_blank&quot;&gt;ftp://ftp.perforce.com/perforce/&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;Documentation:&lt;br&gt;&lt;ul&gt;&lt;li&gt;Main Page:  &lt;a class=&quot;externalLink&quot; href=&quot;http://www.perforce.com/perforce/technical.html&quot; title=&quot;External link to http://www.perforce.com/perforce/technical.html&quot; target=&quot;_blank&quot;&gt;http://www.perforce.com/perforce/technical.html&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Python specific HTML: &lt;a class=&quot;externalLink&quot; href=&quot;http://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html#1116373&quot; title=&quot;External link to http://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html#1116373&quot; target=&quot;_blank&quot;&gt;http://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html#1116373&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Multi-language .pdf:  &lt;a class=&quot;externalLink&quot; href=&quot;http://www.perforce.com/perforce/doc.current/manuals/p4script/p4script.pdf&quot; title=&quot;External link to http://www.perforce.com/perforce/doc.current/manuals/p4script/p4script.pdf&quot; target=&quot;_blank&quot;&gt;http://www.perforce.com/perforce/doc.current/manuals/p4script/p4script.pdf&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;Informative Blog Posts:&lt;br&gt;&lt;ul&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://www.chrisevans3d.com/pub_blog/?p=55&quot; title=&quot;External link to http://www.chrisevans3d.com/pub_blog/?p=55&quot; target=&quot;_blank&quot;&gt;Perforce Triggers in Python (part 1)&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://www.chrisevans3d.com/pub_blog/?p=571&quot; title=&quot;External link to http://www.chrisevans3d.com/pub_blog/?p=571&quot; target=&quot;_blank&quot;&gt;Perforce Triggers in Python (part 2)&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://www.chrisevans3d.com/pub_blog/?p=584&quot; title=&quot;External link to http://www.chrisevans3d.com/pub_blog/?p=584&quot; target=&quot;_blank&quot;&gt;Writing Custom Perforce Plugins in Python&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://techarttiki.blogspot.com/2012/03/perforce-python-api-basics.html&quot; title=&quot;External link to http://techarttiki.blogspot.com/2012/03/perforce-python-api-basics.html&quot; target=&quot;_blank&quot;&gt;Perforce Python API Basics&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;The install appears to stick the modules here:&lt;br&gt;&lt;pre&gt;C:\Python25\Lib\site-packages\

P4.py
p4.pyc
p4.pyo
P4API.pyd
P4Python-2007.3-py2.5.egg-info
&lt;/pre&gt;Some example code modified from their manual (they had... mistakes...)&lt;br&gt;&lt;pre&gt;from P4 import P4, P4Exception

p4 = P4()
p4.port = &quot;myPort:1666&quot;
p4.user = &quot;myName&quot;
p4.client = &quot;myClient&quot;
try:
	p4.connect()
	info = p4.run(&quot;info&quot;) # returns a list
	d = info[0]  # extract the dictionary
	for key in d.keys():   # print our 'info'
		print key + &quot;  :  &quot; + str(d[key])
	p4.disconnect()
except P4Exception:
	for e in p4.errors:
		print e
&lt;/pre&gt;&lt;hr&gt;&lt;strong&gt;Notes:&lt;/strong&gt;&lt;br&gt;&lt;ul&gt;&lt;li&gt;It appears that most of P4's commands are wrappered in methods that start with &lt;code&gt;run_&lt;/code&gt;, or can be called to via the &lt;code&gt;run()&lt;/code&gt; method (as in the example above):&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;info = p4.run(&quot;info&quot;)
info = p4.run_info()
# Both appear to do the same thing. 
&lt;/pre&gt;&lt;pre&gt;# Both do the same thing, but sometimes run takes extra args:
files = p4.run_edit([r&quot;c:\myFile.txt&quot;, r&quot;c:\myFileB.txt])
files = p4.run(&quot;edit&quot;, [r&quot;c:\myFile.txt&quot;, r&quot;c:\myFileB.txt])
&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;I've also ran into issues that some commands run much faster than others based on the &lt;code&gt;run()&lt;/code&gt; syntax.&lt;/li&gt;&lt;li&gt;For example, &lt;code&gt;p4.run('print')&lt;/code&gt; executes &lt;em&gt;much faster&lt;/em&gt; than &lt;code&gt;p4.run_print()&lt;/code&gt;.  &lt;/li&gt;&lt;/ul&gt;&lt;br&gt;</description>
<category>P4</category>
<category>perforce</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BPerforce%20access%20via%20Python%5D%5D</link>
<pubDate>Mon, 06 May 2013 20:53:00 GMT</pubDate>
</item>
<item>
<title>How can I sync to a Perforce changelist?</title>
<description>Came up with two different ways, one via the API, and one via the system.  The API is nice, but I can't find any way to extract the results.  Could just be my ignorance.  Calling to P4 at the system level makes it easy to get the results:&lt;br&gt;&lt;pre&gt;# Via the P4 API:
import P4
changelist = 1234
p4 = P4.P4()
p4.connect()
# Only raise exceptions, not warnings
p4.exception_level = 1
print &quot;Starting P4 sync for changelist %s&quot;%changelist
p4.run_sync('@=%s'%changelist)
p4.disconnect()
&lt;/pre&gt;&lt;pre&gt;# Via calls to the system:
import subprocess
changelist = 1234
print &quot;Starting P4 sync for changelist %s&quot;%changelist
result  = subprocess.Popen(['p4', 'sync', '@=%s'%changelist], 
                           stdout=subprocess.PIPE).communicate()
foo = [f.strip() for f in result[0].split(&quot;\r\n&quot;) if f != &quot;&quot;]
if len(foo):
    for f in foo:
        print &quot;\t&quot;, f
else:
    print &quot;\tEverything is up to date.&quot;
print &quot;Finished P4 changelist sync, see results above:&quot;
&lt;/pre&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html#1116373&quot; title=&quot;External link to http://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html#1116373&quot; target=&quot;_blank&quot;&gt;http://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html#1116373&lt;/a&gt;</description>
<category>P4</category>
<category>perforce</category>
<category>changelist</category>
<category>sync</category>
<category>subprocess</category>
<category>subprocess.Popen</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BHow%20can%20I%20sync%20to%20a%20Perforce%20changelist%3F%5D%5D</link>
<pubDate>Mon, 06 May 2013 20:49:00 GMT</pubDate>
</item>
<item>
<title>How can I query if a file is in Perforce?</title>
<description>If a file lives in Perforce, the &lt;code&gt;fstat&lt;/code&gt; command will return a bunch of info on it.  If it doesn't live in P4, it returns an empty list.&lt;br&gt;Via the Perforce Python API:&lt;br&gt;&lt;pre&gt;import P4
p4 = P4.P4()
# only raise excptions on errors, not warnings:
p4.exception_level = 1
p4.connect()
result = p4.run_fstat(pathToMyFile)
p4.disconnect()
if result:
    print &quot;Lives in P4!&quot;, pathToMyFile
else:
    print &quot;Not in P4!&quot;, pathToMyFile
&lt;/pre&gt;</description>
<category>P4</category>
<category>perforce</category>
<category>file</category>
<category>P4.run_fstat</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BHow%20can%20I%20query%20if%20a%20file%20is%20in%20Perforce%3F%5D%5D</link>
<pubDate>Mon, 06 May 2013 20:49:00 GMT</pubDate>
</item>
<item>
<title>MainMenu</title>
<description>&lt;div class=&quot;gradient&quot; style=&quot;position: relative; overflow: hidden; z-index: 0;&quot;&gt;&lt;div style=&quot;position: absolute; left: 0%; top: 0px; width: 101%; height: 100%; z-index: -1; background-color: rgb(221, 221, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 2%; top: 0px; width: 99%; height: 100%; z-index: -1; background-color: rgb(221, 221, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 4%; top: 0px; width: 97%; height: 100%; z-index: -1; background-color: rgb(222, 222, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 6%; top: 0px; width: 95%; height: 100%; z-index: -1; background-color: rgb(223, 223, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 8%; top: 0px; width: 93%; height: 100%; z-index: -1; background-color: rgb(223, 223, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 10%; top: 0px; width: 91%; height: 100%; z-index: -1; background-color: rgb(224, 224, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 12%; top: 0px; width: 89%; height: 100%; z-index: -1; background-color: rgb(225, 225, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 14%; top: 0px; width: 87%; height: 100%; z-index: -1; background-color: rgb(225, 225, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 16%; top: 0px; width: 85%; height: 100%; z-index: -1; background-color: rgb(226, 226, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 18%; top: 0px; width: 83%; height: 100%; z-index: -1; background-color: rgb(227, 227, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 20%; top: 0px; width: 81%; height: 100%; z-index: -1; background-color: rgb(227, 227, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 22%; top: 0px; width: 79%; height: 100%; z-index: -1; background-color: rgb(228, 228, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 24%; top: 0px; width: 77%; height: 100%; z-index: -1; background-color: rgb(229, 229, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 26%; top: 0px; width: 75%; height: 100%; z-index: -1; background-color: rgb(229, 229, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 28%; top: 0px; width: 73%; height: 100%; z-index: -1; background-color: rgb(230, 230, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 30%; top: 0px; width: 71%; height: 100%; z-index: -1; background-color: rgb(231, 231, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 32%; top: 0px; width: 69%; height: 100%; z-index: -1; background-color: rgb(231, 231, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 34%; top: 0px; width: 67%; height: 100%; z-index: -1; background-color: rgb(232, 232, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 36%; top: 0px; width: 65%; height: 100%; z-index: -1; background-color: rgb(233, 233, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 38%; top: 0px; width: 63%; height: 100%; z-index: -1; background-color: rgb(233, 233, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 40%; top: 0px; width: 61%; height: 100%; z-index: -1; background-color: rgb(234, 234, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 42%; top: 0px; width: 59%; height: 100%; z-index: -1; background-color: rgb(235, 235, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 44%; top: 0px; width: 57%; height: 100%; z-index: -1; background-color: rgb(235, 235, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 46%; top: 0px; width: 55%; height: 100%; z-index: -1; background-color: rgb(236, 236, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 48%; top: 0px; width: 53%; height: 100%; z-index: -1; background-color: rgb(237, 237, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 50%; top: 0px; width: 51%; height: 100%; z-index: -1; background-color: rgb(238, 238, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 52%; top: 0px; width: 49%; height: 100%; z-index: -1; background-color: rgb(238, 238, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 54%; top: 0px; width: 47%; height: 100%; z-index: -1; background-color: rgb(239, 239, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 56%; top: 0px; width: 45%; height: 100%; z-index: -1; background-color: rgb(240, 240, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 58%; top: 0px; width: 43%; height: 100%; z-index: -1; background-color: rgb(240, 240, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 60%; top: 0px; width: 41%; height: 100%; z-index: -1; background-color: rgb(241, 241, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 62%; top: 0px; width: 39%; height: 100%; z-index: -1; background-color: rgb(242, 242, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 64%; top: 0px; width: 37%; height: 100%; z-index: -1; background-color: rgb(242, 242, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 66%; top: 0px; width: 35%; height: 100%; z-index: -1; background-color: rgb(243, 243, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 68%; top: 0px; width: 33%; height: 100%; z-index: -1; background-color: rgb(244, 244, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 70%; top: 0px; width: 31%; height: 100%; z-index: -1; background-color: rgb(244, 244, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 72%; top: 0px; width: 29%; height: 100%; z-index: -1; background-color: rgb(245, 245, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 74%; top: 0px; width: 27%; height: 100%; z-index: -1; background-color: rgb(246, 246, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 76%; top: 0px; width: 25%; height: 100%; z-index: -1; background-color: rgb(246, 246, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 78%; top: 0px; width: 23%; height: 100%; z-index: -1; background-color: rgb(247, 247, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 80%; top: 0px; width: 21%; height: 100%; z-index: -1; background-color: rgb(248, 248, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 82%; top: 0px; width: 19%; height: 100%; z-index: -1; background-color: rgb(248, 248, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 84%; top: 0px; width: 17%; height: 100%; z-index: -1; background-color: rgb(249, 249, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 86%; top: 0px; width: 15%; height: 100%; z-index: -1; background-color: rgb(250, 250, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 88%; top: 0px; width: 13%; height: 100%; z-index: -1; background-color: rgb(250, 250, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 90%; top: 0px; width: 11%; height: 100%; z-index: -1; background-color: rgb(251, 251, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 92%; top: 0px; width: 9%; height: 100%; z-index: -1; background-color: rgb(252, 252, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 94%; top: 0px; width: 7%; height: 100%; z-index: -1; background-color: rgb(252, 252, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 96%; top: 0px; width: 5%; height: 100%; z-index: -1; background-color: rgb(253, 253, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 98%; top: 0px; width: 3%; height: 100%; z-index: -1; background-color: rgb(254, 254, 255);&quot;&gt;&lt;/div&gt;&lt;div style=&quot;position: absolute; left: 100%; top: 0px; width: 1%; height: 100%; z-index: -1; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#Welcome&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#Welcome&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;Welcome&quot;&gt;Welcome&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#About python tiddlywiki&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#About python tiddlywiki&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;About python tiddlywiki&quot;&gt;About wiki&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#Instructions for use&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#Instructions for use&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;Instructions for use&quot;&gt;Instructions for use&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#History&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#History&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;History&quot;&gt;Latest Updates&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#Python Links&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#Python Links&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;Python Links&quot;&gt;Python Links&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#WarpCat&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#WarpCat&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;WarpCat&quot;&gt;About author&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#Copyright Information&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#Copyright Information&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;Copyright Information&quot;&gt;Copyright Information&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;strong&gt;Subscribe&lt;/strong&gt;:&lt;br&gt;&lt;strong&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com/index.xml&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com/index.xml&quot; target=&quot;_blank&quot;&gt;RSS&lt;/a&gt;&lt;/strong&gt; &lt;a class=&quot;externalLink imageLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com/index.xml&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com/index.xml&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://farm1.static.flickr.com/197/492915948_b4a9f3233e.jpg?v=0&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;hr&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#All Subjects&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#All Subjects&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;All Subjects&quot;&gt;All Subjects&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;strong&gt;Categories:&lt;/strong&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#DICTIONARY&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#DICTIONARY&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;DICTIONARY&quot;&gt;DICTIONARY&lt;/a&gt; &lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#ENVIRONMENT&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#ENVIRONMENT&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;ENVIRONMENT&quot;&gt;ENVIRONMENT&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#EXECUTION&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#EXECUTION&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;EXECUTION&quot;&gt;EXECUTION&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#EXTERNAL APPS&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#EXTERNAL APPS&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;EXTERNAL APPS&quot;&gt;EXTERNAL APPS&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#FILESYSTEMS&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#FILESYSTEMS&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;FILESYSTEMS&quot;&gt;FILESYSTEMS&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#FUNDAMENTALS&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#FUNDAMENTALS&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;FUNDAMENTALS&quot;&gt;FUNDAMENTALS&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#INFO&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#INFO&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;INFO&quot;&gt;INFO&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#I/O&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#I/O&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;I/O&quot;&gt;I/O&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#KIVY&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#KIVY&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;KIVY&quot;&gt;KIVY&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#LIST&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#LIST&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;LIST&quot;&gt;LIST&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#MATH&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#MATH&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;MATH&quot;&gt;MATH&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#MATPLOTLIB&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#MATPLOTLIB&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;MATPLOTLIB&quot;&gt;MATPLOTLIB&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#MEDIA&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#MEDIA&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;MEDIA&quot;&gt;MEDIA&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#NETWORK&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#NETWORK&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;NETWORK&quot;&gt;NETWORK&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#NUMBERS&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#NUMBERS&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;NUMBERS&quot;&gt;NUMBERS&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#NUMPY&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#NUMPY&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;NUMPY&quot;&gt;NUMPY&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#OOP&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#OOP&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;OOP&quot;&gt;OOP&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#PIL&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#PIL&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;PIL&quot;&gt;PIL&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#P4&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#P4&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;P4&quot;&gt;P4&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#PYGAME&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#PYGAME&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;PYGAME&quot;&gt;PYGAME&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#RASPBERRY PI&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#RASPBERRY PI&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;RASPBERRY PI&quot;&gt;RASPBERRY PI&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#SCIPY&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#SCIPY&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;SCIPY&quot;&gt;SCIPY&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#STRING&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#STRING&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;STRING&quot;&gt;STRING&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#TROUBLESHOOTING&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#TROUBLESHOOTING&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;TROUBLESHOOTING&quot;&gt;TROUBLESHOOTING&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#UI&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#UI&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;UI&quot;&gt;UI&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#VARIABLES&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#VARIABLES&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;VARIABLES&quot;&gt;VARIABLES&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#WEB&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#WEB&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;WEB&quot;&gt;WEB&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#XML&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#XML&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;XML&quot;&gt;XML&lt;/a&gt;&lt;br&gt;&lt;/div&gt;</description>
<category>wiki</category>
<link>http://pythonwiki.tiddlyspot.com#MainMenu</link>
<pubDate>Mon, 06 May 2013 20:48:00 GMT</pubDate>
</item>
<item>
<title>pickle, protocol, and perforce</title>
<description>&lt;a class=&quot;externalLink&quot; href=&quot;http://docs.python.org/library/pickle.html&quot; title=&quot;External link to http://docs.python.org/library/pickle.html&quot; target=&quot;_blank&quot;&gt;http://docs.python.org/library/pickle.html&lt;/a&gt;&lt;br&gt;I recently had an issue where I'd &lt;code&gt;pickle&lt;/code&gt; some data to disk, and add the data to Perforce (P4) so others could access.  But when the other team members would sync to the data, they couldn't use it.  They'd get an exception with this info:&lt;br&gt;&lt;pre&gt;No module named copy_reg
&lt;/pre&gt;Looking online the common fix was to make sure your data was pickled in binary format. But this didn't help.&lt;br&gt;Doing some research, I found that the size of the file would get bigger after checking into P4, although when I'd diff the file it would say there were no differences.  The plot thickens....&lt;br&gt;&lt;br&gt;Talking with our IT department, they came to the idea that maybe P4 was changing the line ending of the files:  If you open your Clientspec in P4, there is a 'LineEnd' drop-down, mine was set to 'local'.  Changing this to 'unix' and resubmitting the file suddenly fixed the problem.  But we couldn't have our whole team make this change, especially not knowing what other repercussions it may have, so I set it back.&lt;br&gt; &lt;br&gt;So we took a look at the &lt;code&gt;pickle&lt;/code&gt; docs.  Come to find out, introduced in Python 2.3, there was a new 'protocol' arg provided (protocol '2') which according to the docs: &quot;...provides much more efficient pickling of new-style classes.&quot;.&lt;br&gt;&lt;br&gt;The original code was this:&lt;br&gt;&lt;pre&gt;outf = open(dataFile, 'wb')
pickle.dump(data, outf)
outf.close()
&lt;/pre&gt;The new code is this:&lt;br&gt;&lt;pre&gt;outf = open(dataFile, 'wb')
pickle.dump(data, outf, 2)
outf.close()
&lt;/pre&gt;Setting that new protocol value fixed the problem:  The data could be added to P4, other team-members could access it no problem.&lt;br&gt;&lt;br&gt;</description>
<category>P4</category>
<category>TROUBLESHOOTING</category>
<category>FILESYSTEMS</category>
<category>pickle</category>
<category>cPickle</category>
<category>perforce</category>
<category>protocol</category>
<category>line ending</category>
<category>return character</category>
<category>newline</category>
<category>copy_reg</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5Bpickle%2C%20protocol%2C%20and%20perforce%5D%5D</link>
<pubDate>Mon, 06 May 2013 20:48:00 GMT</pubDate>
</item>
<item>
<title>How can I make custom changelists in Perforce, and have Python know what number they are?</title>
<description>If you're wondering:  &lt;a class=&quot;externalLink&quot; href=&quot;http://www.perforce.com/&quot; title=&quot;External link to http://www.perforce.com/&quot; target=&quot;_blank&quot;&gt;http://www.perforce.com/&lt;/a&gt;&lt;br&gt;&lt;h3&gt;Via the Perforce &lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#Perforce access via Python&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#Perforce access via Python&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;Perforce access via Python&quot;&gt;API&lt;/a&gt;:&lt;/h3&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html#1116373&quot; title=&quot;External link to http://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html#1116373&quot; target=&quot;_blank&quot;&gt;P4 API Docs&lt;/a&gt;&lt;br&gt;This will both create a changelist, and optionally add files to it.  The file add system is terribly limited:  It will only work on files already existing in P4, that aren't already open for edit.  You'd need to write a more robust set of conditions to work with files that are to be added, files that live in another changelist, files that should be deleted, or files that someone else has checked out.  But it gives you an idea for where to start...&lt;br&gt;Thanks to an email from Ross Kameny got me this code snippet:&lt;br&gt;&lt;pre&gt;import P4

def makeChangelist(description, files=[]):
    &quot;&quot;&quot;
    description : string : The changelist description
    files : list : The files to edit.  Default is an empty list.
    &quot;&quot;&quot;
    p4 = P4.P4()
    p4.connect()
    if files:
        p4.run_edit(files)
    changeList = p4.fetch_change()
    changeList[&quot;Description&quot;] = description
    if files:
        changeList[&quot;Files&quot;] = files
    results = p4.save_change(changeList)
    changelistNum = int(results[0].split(' ')[1])
    p4.disconnect()

    return changelistNum
&lt;/pre&gt;&lt;h3&gt;Via calls to the system:&lt;/h3&gt;This just makes an empty changelist, doesn't add any files to it.&lt;br&gt;First, you need to generate a text file with the change info in it, and save it. Like &lt;code&gt;c:/temp/myChangelist.txt&lt;/code&gt;:&lt;br&gt;&lt;pre&gt;Change:  new
Description:
      Enter description here, one line
&lt;/pre&gt;Then in Python, call to P4 to create the changelist, then find the changelist number (to be used to add things to the list):&lt;br&gt;&lt;pre&gt;import os
p4changeReturn = os.popen(&quot;P4 change -i &amp;lt; c:/temp/myChangelist.txt&quot;).read().strip()
buffer = p4changeReturn.split(&quot; &quot;)
changelistNumber = buffer[1]
&lt;/pre&gt;FYI:  In Python 2.6 and newer, &lt;code&gt;popen&lt;/code&gt; is depricated.  Check notes on &lt;code&gt;subprocess&lt;/code&gt; &lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#How can I execute a system command, and capture the return?&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#How can I execute a system command, and capture the return?&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;How can I execute a system command, and capture the return?&quot;&gt;here&lt;/a&gt;</description>
<category>P4</category>
<category>perforce</category>
<category>os</category>
<category>os.popen</category>
<category>file.read</category>
<category>string.strip</category>
<category>string.split</category>
<category>changelist</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BHow%20can%20I%20make%20custom%20changelists%20in%20Perforce%2C%20and%20have%20Python%20know%20what%20number%20they%20are%3F%5D%5D</link>
<pubDate>Mon, 06 May 2013 20:48:00 GMT</pubDate>
</item>
<item>
<title>Delete all empty changelists in Perforce for current client</title>
<description>I'm always surprised that the Perfoce ui doesn't give the user the option to delete all empty changelists.  Here's a simple function that will do it via the P4 API.  See &lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#Perforce access via Python&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#Perforce access via Python&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;Perforce access via Python&quot;&gt;Perforce access via Python&lt;/a&gt;.&lt;br&gt;&lt;pre&gt;import P4

def deleteEmptyChangelists():
    p4 = P4.P4()
    # User needs to handle p4.errors &amp;amp; p4.warnings (not done in this code):
    p4.exception_level = 0
    p4.connect()
    # Get all current changes for this client:
    data = p4.run(&quot;changes&quot;, &quot;-s&quot;, &quot;pending&quot;, &quot;-c&quot;, p4.client)

    emptyChange = []
    for d in data:
        if 'shelved' in d:
            # Archived\shelved, skip
            continue

        # Find files in this change:
        files = p4.run(&quot;describe&quot;, d['change'])
        if 'depotFile' not in files[0]:
            emptyChange.append(d['change'])

    if emptyChange:
        for empty in emptyChange:
            # Need to loop, can't delete multiple changes at once:
            p4.run(&quot;change&quot;, &quot;-d&quot;, empty)
        print &quot;Deleted empty changelists:&quot;, emptyChange
    else:
        print &quot;No empty changelists to delete.&quot;

    p4.disconnect()
    return emptyChange
&lt;/pre&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html#1116373&quot; title=&quot;External link to http://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html#1116373&quot; target=&quot;_blank&quot;&gt;Perforce Python API docs&lt;/a&gt;</description>
<category>P4</category>
<category>perforce</category>
<category>changelist</category>
<category>empty</category>
<category>change</category>
<category>changes</category>
<category>describe</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BDelete%20all%20empty%20changelists%20in%20Perforce%20for%20current%20client%5D%5D</link>
<pubDate>Mon, 06 May 2013 20:48:00 GMT</pubDate>
</item>
<item>
<title>Accessing user temp directory and files</title>
<description>(On the Windows system at least...) this directory is stored in the system variable &lt;code&gt;TMP&lt;/code&gt; or &lt;code&gt;TEMP&lt;/code&gt;.&lt;br&gt;&lt;hr&gt;Create a name for a file in the users temp directory:&lt;br&gt;&lt;pre&gt;import os

# TMPDIR on mac
tempfile = os.path.join(os.getenv(&quot;TMP&quot;), &quot;tempfile.txt&quot;)
print tempfile
&lt;/pre&gt;On Vista:&lt;br&gt;&lt;pre&gt;C:\Users\&amp;lt;USERNAME&amp;gt;\AppData\Local\Temp\tempfile.txt
&lt;/pre&gt;On Mac:&lt;br&gt;&lt;pre&gt;/var/folders/kv/dk8t43d535s3pvw9z_8zhh2c0000gn/T/tempfile.ma
&lt;/pre&gt;&lt;hr&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://docs.python.org/library/tempfile.html&quot; title=&quot;External link to http://docs.python.org/library/tempfile.html&quot; target=&quot;_blank&quot;&gt;http://docs.python.org/library/tempfile.html&lt;/a&gt;&lt;br&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://blog.doughellmann.com/2008/02/pymotw-tempfile.html&quot; title=&quot;External link to http://blog.doughellmann.com/2008/02/pymotw-tempfile.html&quot; target=&quot;_blank&quot;&gt;http://blog.doughellmann.com/2008/02/pymotw-tempfile.html&lt;/a&gt;&lt;br&gt;&lt;br&gt;</description>
<category>FILESYSTEMS</category>
<category>ENVIRONMENT</category>
<category>tmp</category>
<category>mac</category>
<category>temp</category>
<category>temporary file</category>
<category>directory</category>
<category>os</category>
<category>os.path</category>
<category>os.path.join</category>
<category>os.getenv</category>
<category>tempfile</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BAccessing%20user%20temp%20directory%20and%20files%5D%5D</link>
<pubDate>Tue, 09 Apr 2013 00:05:00 GMT</pubDate>
</item>
<item>
<title>How can I get a list of Environment Variables?</title>
<description>&lt;code&gt;os.environ&lt;/code&gt; returns a &lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#DICTIONARY&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#DICTIONARY&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;DICTIONARY&quot;&gt;Dictionary&lt;/a&gt;&lt;br&gt;&lt;pre&gt;import os
for key in os.environ:
    print key + &quot; : &quot; + os.environ[key]
&lt;/pre&gt;Also see:&lt;br&gt;&lt;ul&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#How can I query the value of an Environment Variable?&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#How can I query the value of an Environment Variable?&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;How can I query the value of an Environment Variable?&quot;&gt;How can I query the value of an Environment Variable?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#How can I set an environment variable?&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#How can I set an environment variable?&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;How can I set an environment variable?&quot;&gt;How can I set an environment variable?&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;</description>
<category>ENVIRONMENT</category>
<category>os</category>
<category>os.environ</category>
<category>environment variables</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BHow%20can%20I%20get%20a%20list%20of%20Environment%20Variables%3F%5D%5D</link>
<pubDate>Tue, 19 Mar 2013 16:30:00 GMT</pubDate>
</item>
<item>
<title>How can I set an environment variable?</title>
<description>If you can query an environment variable via &lt;a class=&quot;externalLink&quot; href=&quot;http://docs.python.org/2/library/os.html#os.getenv&quot; title=&quot;External link to http://docs.python.org/2/library/os.html#os.getenv&quot; target=&quot;_blank&quot;&gt;os.getenv&lt;/a&gt; like so:&lt;br&gt;&lt;pre&gt;import os
myvar = os.getenv(&quot;MYVAR&quot;)
&lt;/pre&gt;You'd &lt;em&gt;think&lt;/em&gt; you'd be able to able to set one like the same way, via &lt;a class=&quot;externalLink&quot; href=&quot;http://docs.python.org/2/library/os.html#os.putenv&quot; title=&quot;External link to http://docs.python.org/2/library/os.html#os.putenv&quot; target=&quot;_blank&quot;&gt;os.putenv&lt;/a&gt;:&lt;br&gt;&lt;pre&gt;os.putenv(&quot;MYVAR&quot;, &quot;my var value&quot;) 
&lt;/pre&gt;On Windows however, &lt;code&gt;putenv&lt;/code&gt; doesn't seem to do anything.... :-S&lt;br&gt;&lt;br&gt;To actually update the var, you need to update via &lt;a class=&quot;externalLink&quot; href=&quot;http://docs.python.org/2/library/os.html#os.environ&quot; title=&quot;External link to http://docs.python.org/2/library/os.html#os.environ&quot; target=&quot;_blank&quot;&gt;os.environ&lt;/a&gt;&lt;br&gt;&lt;pre&gt;os.environ[&quot;MYVAR&quot;] = &quot;my var value&quot;)
&lt;/pre&gt;&lt;hr&gt;Also see:&lt;br&gt;&lt;ul&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#How can I get a list of Environment Variables?&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#How can I get a list of Environment Variables?&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;How can I get a list of Environment Variables?&quot;&gt;How can I get a list of Environment Variables?&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;</description>
<category>ENVIRONMENT</category>
<category>TROUBLESHOOTING</category>
<category>os</category>
<category>os.getenv</category>
<category>os.putenv</category>
<category>os.environ</category>
<category>environment variable</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BHow%20can%20I%20set%20an%20environment%20variable%3F%5D%5D</link>
<pubDate>Tue, 19 Mar 2013 16:30:00 GMT</pubDate>
</item>
<item>
<title>How can I query the value of an Environment Variable?</title>
<description>&lt;code&gt;os.environ&lt;/code&gt; returns a &lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#DICTIONARY&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#DICTIONARY&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;DICTIONARY&quot;&gt;Dictionary&lt;/a&gt;&lt;br&gt;&lt;pre&gt;import os
var = os.getenv(&quot;PATH&quot;)
&lt;/pre&gt;&lt;hr&gt;Also see: &lt;br&gt;&lt;ul&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#How can I get a list of Environment Variables?&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#How can I get a list of Environment Variables?&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;How can I get a list of Environment Variables?&quot;&gt;How can I get a list of Environment Variables?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://pythonwiki.tiddlyspot.com#How can I set an environment variable?&quot; title=&quot;External link to http://pythonwiki.tiddlyspot.com#How can I set an environment variable?&quot; target=&quot;_blank&quot; refresh=&quot;link&quot; tiddlylink=&quot;How can I set an environment variable?&quot;&gt;How can I set an environment variable?&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;</description>
<category>ENVIRONMENT</category>
<category>os</category>
<category>os.getenv</category>
<category>environment variables</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BHow%20can%20I%20query%20the%20value%20of%20an%20Environment%20Variable%3F%5D%5D</link>
<pubDate>Tue, 19 Mar 2013 16:29:00 GMT</pubDate>
</item>
<item>
<title>Pre-packaged Python distributions</title>
<description>There are a number of &quot;Precompiled Python Distributions&quot; available.  There is a complete list &lt;a class=&quot;externalLink&quot; href=&quot;http://wiki.python.org/moin/PythonDistributions&quot; title=&quot;External link to http://wiki.python.org/moin/PythonDistributions&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.  Two of the more popular ones are:&lt;br&gt;&lt;ul&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://www.enthought.com/products/epd_free.php&quot; title=&quot;External link to http://www.enthought.com/products/epd_free.php&quot; target=&quot;_blank&quot;&gt;Enthought Python Distribution&lt;/a&gt; (free version)&lt;/li&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://www.activestate.com/activepython&quot; title=&quot;External link to http://www.activestate.com/activepython&quot; target=&quot;_blank&quot;&gt;ActiveState ActivePython&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class=&quot;externalLink&quot; href=&quot;http://www.portablepython.com/&quot; title=&quot;External link to http://www.portablepython.com/&quot; target=&quot;_blank&quot;&gt;Portable Python&lt;/a&gt;&lt;ul&gt;&lt;li&gt;A list of what packages it has can be found for each of its downloads: &lt;a class=&quot;externalLink&quot; href=&quot;http://portablepython.com/wiki/PortablePython2.7.3.2&quot; title=&quot;External link to http://portablepython.com/wiki/PortablePython2.7.3.2&quot; target=&quot;_blank&quot;&gt;2.x&lt;/a&gt;, &lt;a class=&quot;externalLink&quot; href=&quot;http://portablepython.com/wiki/PortablePython3.2.1.1&quot; title=&quot;External link to http://portablepython.com/wiki/PortablePython3.2.1.1&quot; target=&quot;_blank&quot;&gt;3.x&lt;/a&gt; (those links are bound to stale, navigate from their home page for latest).&lt;/li&gt;&lt;li&gt;It's Windows only :(&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;</description>
<category>ENVIRONMENT</category>
<category>distribution</category>
<category>enthought</category>
<category>activepython</category>
<category>portable python</category>
<link>http://pythonwiki.tiddlyspot.com#%5B%5BPre-packaged%20Python%20distributions%5D%5D</link>
<pubDate>Mon, 04 Mar 2013 19:36:00 GMT</pubDate>
</item>
</channel>
</rss>