title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Limiting the results of cProfile to lines containing "something" _and/or_ "something_else"
695,501
<p>I am using cProfile to profile the leading function of my entire app. It's working great except for some 3rd party libraries that are being profiled, and shown in the output as well. This is not always desirable when reading the output.</p> <p>My question is, how can i limit this? The <a href="http://docs.python.or...
0
2009-03-29T22:22:58Z
695,711
<p>Per the docs you linked, the strings are regular expressions:</p> <blockquote> <p>Each restriction is either an integer ..., or a regular expression (to pattern match the standard name that is printed; as of Python 1.5b1, this uses the Perl-style regular expression syntax defined by the re module)</p> <...
0
2009-03-30T00:48:44Z
[ "python" ]
Parsing template schema with Python and Regular Expressions
695,505
<p>I'm working on a script for work to extract data from an old template engine schema: </p> <pre><code>[%price%] { $54.99 } [%/price%] [%model%] { WRT54G } [%/model%] [%brand%]{ LINKSYS } [%/brand%] </code></pre> <p>everything within the [% %] is the key, and everything in the { } is the value. Using Python and re...
0
2009-03-29T22:24:44Z
695,508
<p>It looks like it'd be easier to do with <code>re.Scanner</code> (sadly undocumented) than with a single regular expression.</p>
0
2009-03-29T22:27:23Z
[ "python", "regex", "parsing", "grouping" ]
Parsing template schema with Python and Regular Expressions
695,505
<p>I'm working on a script for work to extract data from an old template engine schema: </p> <pre><code>[%price%] { $54.99 } [%/price%] [%model%] { WRT54G } [%/model%] [%brand%]{ LINKSYS } [%/brand%] </code></pre> <p>everything within the [% %] is the key, and everything in the { } is the value. Using Python and re...
0
2009-03-29T22:24:44Z
695,520
<p>I agree with Devin that a single regex isn't the best solution. If there do happen to be any strange cases that aren't handled by your regex, there's a real risk that you won't find out.</p> <p>I'd suggest using a finite state machine approach. Parse the file line by line, first looking for a price-model-brand bloc...
4
2009-03-29T22:34:29Z
[ "python", "regex", "parsing", "grouping" ]
Parsing template schema with Python and Regular Expressions
695,505
<p>I'm working on a script for work to extract data from an old template engine schema: </p> <pre><code>[%price%] { $54.99 } [%/price%] [%model%] { WRT54G } [%/model%] [%brand%]{ LINKSYS } [%/brand%] </code></pre> <p>everything within the [% %] is the key, and everything in the { } is the value. Using Python and re...
0
2009-03-29T22:24:44Z
695,553
<p>just for grins:</p> <pre><code>import re RE_kv = re.compile("\[%(.*)%\].*?\n?\s*{\s*(.*)") matches = re.findall(RE_kv, test, re.M) for k, v in matches: print k, v </code></pre> <p>output:</p> <pre><code>price $54.99 model WRT54G brand LINKSYS </code></pre> <p>Note I did just enough regex to get the matches t...
0
2009-03-29T22:52:13Z
[ "python", "regex", "parsing", "grouping" ]
How to distinguish between a function and a class method?
695,679
<p>If a variable refers to either a function or a class method, how can I find out which one it is and get the class type in case it is a class method especially when the class is still being declared as in the given example.</p> <p>eg.</p> <pre> def get_info(function_or_method) : print function_or_method...
4
2009-03-30T00:16:10Z
695,694
<p>You can distinguish between the two by checking the type:</p> <pre><code>&gt;&gt;&gt; type(bar) &lt;type 'function'&gt; &gt;&gt;&gt; type(Foo.__init__) &lt;type 'instancemethod'&gt; </code></pre> <p>or</p> <pre><code>&gt;&gt;&gt; import types &gt;&gt;&gt; isinstance(bar, types.FunctionType) True &gt;&gt;&gt; isin...
11
2009-03-30T00:29:51Z
[ "python", "reflection", "metaprogramming" ]
How to distinguish between a function and a class method?
695,679
<p>If a variable refers to either a function or a class method, how can I find out which one it is and get the class type in case it is a class method especially when the class is still being declared as in the given example.</p> <p>eg.</p> <pre> def get_info(function_or_method) : print function_or_method...
4
2009-03-30T00:16:10Z
695,704
<p>At the time you are calling <code>get_info(__init__)</code> (inside class definition) the <code>__init__</code> is an ordinary function.</p> <pre><code>def get_info(function_or_method): print function_or_method class Foo(object): def __init__(self): pass get_info(__init__) # function def bar...
8
2009-03-30T00:42:17Z
[ "python", "reflection", "metaprogramming" ]
How to distinguish between a function and a class method?
695,679
<p>If a variable refers to either a function or a class method, how can I find out which one it is and get the class type in case it is a class method especially when the class is still being declared as in the given example.</p> <p>eg.</p> <pre> def get_info(function_or_method) : print function_or_method...
4
2009-03-30T00:16:10Z
696,285
<blockquote> <p>To reemphasize a point which J.F. Sebastian alluded to, I want to be able to distinguish it when the function is being declared within the class (when the type I am getting is a function and not a bound or unbound method). ie. where the first call to <code>get_info(__init__)</code> happens I would lik...
3
2009-03-30T07:20:29Z
[ "python", "reflection", "metaprogramming" ]
Google Data API authentication
695,703
<p>I am trying to get my Django app (NOT using Google app engine) retrieve data from Google Contacts using Google Contacts Data API. Going through <a href="http://code.google.com/apis/accounts/docs/AuthSub.html" rel="nofollow">authentication documentation</a> as well as <a href="http://code.google.com/apis/contacts/doc...
6
2009-03-30T00:38:25Z
709,992
<p>According to the 2.0 documentation <a href="http://code.google.com/apis/contacts/docs/2.0/developers_guide_protocol.html#auth_sub" rel="nofollow">here</a> there is a python example set...</p> <blockquote> <p>Running the sample code</p> <p>A full working sample client, containing all the sample code shown in ...
4
2009-04-02T14:43:43Z
[ "python", "django", "google-api", "gdata", "gdata-api" ]
Google Data API authentication
695,703
<p>I am trying to get my Django app (NOT using Google app engine) retrieve data from Google Contacts using Google Contacts Data API. Going through <a href="http://code.google.com/apis/accounts/docs/AuthSub.html" rel="nofollow">authentication documentation</a> as well as <a href="http://code.google.com/apis/contacts/doc...
6
2009-03-30T00:38:25Z
717,259
<p>I had a similar issue recently. Mine got fixed by setting "secure" to "true".</p> <pre><code> next = 'http://www.coolcalendarsite.com/welcome.pyc' scope = 'http://www.google.com/calendar/feeds/' secure = True session = True calendar_service = gdata.calendar.service.CalendarService() </code></pre>
1
2009-04-04T15:26:00Z
[ "python", "django", "google-api", "gdata", "gdata-api" ]
Google Data API authentication
695,703
<p>I am trying to get my Django app (NOT using Google app engine) retrieve data from Google Contacts using Google Contacts Data API. Going through <a href="http://code.google.com/apis/accounts/docs/AuthSub.html" rel="nofollow">authentication documentation</a> as well as <a href="http://code.google.com/apis/contacts/doc...
6
2009-03-30T00:38:25Z
717,283
<p>There are four different ways to authenticate. Is it really that important for you to use AuthSub? If you can't get AuthSub to work, then consider the <a href="http://code.google.com/apis/gdata/auth.html#ClientLogin" rel="nofollow">ClientLogin</a> approach. I had no trouble getting that to work.</p>
1
2009-04-04T15:39:21Z
[ "python", "django", "google-api", "gdata", "gdata-api" ]
more efficient way to pickle a string
695,794
<p>The pickle module seems to use string escape characters when pickling; this becomes inefficient e.g. on numpy arrays. Consider the following</p> <pre><code>z = numpy.zeros(1000, numpy.uint8) len(z.dumps()) len(cPickle.dumps(z.dumps())) </code></pre> <p>The lengths are 1133 characters and 4249 characters respective...
9
2009-03-30T01:48:21Z
695,858
<p>Try using a later version of the pickle protocol with the protocol parameter to <code>pickle.dumps()</code>. The default is 0 and is an ASCII text format. Ones greater than 1 (I suggest you use pickle.HIGHEST_PROTOCOL). Protocol formats 1 and 2 (and 3 but that's for py3k) are binary and should be more space conserva...
23
2009-03-30T02:40:30Z
[ "python", "numpy", "pickle", "space-efficiency" ]
more efficient way to pickle a string
695,794
<p>The pickle module seems to use string escape characters when pickling; this becomes inefficient e.g. on numpy arrays. Consider the following</p> <pre><code>z = numpy.zeros(1000, numpy.uint8) len(z.dumps()) len(cPickle.dumps(z.dumps())) </code></pre> <p>The lengths are 1133 characters and 4249 characters respective...
9
2009-03-30T01:48:21Z
696,716
<p>Solution:</p> <pre><code>import zlib, cPickle def zdumps(obj): return zlib.compress(cPickle.dumps(obj,cPickle.HIGHEST_PROTOCOL),9) def zloads(zstr): return cPickle.loads(zlib.decompress(zstr)) &gt;&gt;&gt; len(zdumps(z)) 128 </code></pre>
8
2009-03-30T10:38:05Z
[ "python", "numpy", "pickle", "space-efficiency" ]
more efficient way to pickle a string
695,794
<p>The pickle module seems to use string escape characters when pickling; this becomes inefficient e.g. on numpy arrays. Consider the following</p> <pre><code>z = numpy.zeros(1000, numpy.uint8) len(z.dumps()) len(cPickle.dumps(z.dumps())) </code></pre> <p>The lengths are 1133 characters and 4249 characters respective...
9
2009-03-30T01:48:21Z
2,799,319
<p>An improvement to vartec's answer, that seems a bit more memory efficient (since it doesn't force everything into a string):</p> <pre><code>def pickle(fname, obj): import cPickle, gzip cPickle.dump(obj=obj, file=gzip.open(fname, "wb", compresslevel=3), protocol=2) def unpickle(fname): import cPickle, g...
1
2010-05-09T21:46:27Z
[ "python", "numpy", "pickle", "space-efficiency" ]
more efficient way to pickle a string
695,794
<p>The pickle module seems to use string escape characters when pickling; this becomes inefficient e.g. on numpy arrays. Consider the following</p> <pre><code>z = numpy.zeros(1000, numpy.uint8) len(z.dumps()) len(cPickle.dumps(z.dumps())) </code></pre> <p>The lengths are 1133 characters and 4249 characters respective...
9
2009-03-30T01:48:21Z
2,808,778
<p><code>z.dumps()</code> is already pickled string i.e., it can be unpickled using pickle.loads():</p> <pre><code>&gt;&gt;&gt; z = numpy.zeros(1000, numpy.uint8) &gt;&gt;&gt; s = z.dumps() &gt;&gt;&gt; a = pickle.loads(s) &gt;&gt;&gt; all(a == z) True </code></pre>
3
2010-05-11T07:26:47Z
[ "python", "numpy", "pickle", "space-efficiency" ]
Re-raise exception with a different type and message, preserving existing information
696,047
<p>I'm writing a module and want to have a unified exception hierarchy for the exceptions that it can raise (e.g. inheriting from a <code>FooError</code> abstract class for all the <code>foo</code> module's specific exceptions). This allows users of the module to catch those particular exceptions and handle them distin...
41
2009-03-30T05:04:34Z
696,087
<p>You could create your own exception type that extends <a href="http://docs.python.org/library/exceptions.html">whichever exception</a> you've caught.</p> <pre><code>class NewException(CaughtException): def __init__(self, caught): self.caught = caught try: ... except CaughtException as e: ... ...
8
2009-03-30T05:38:00Z
[ "python", "exception-handling", "polymorphism" ]
Re-raise exception with a different type and message, preserving existing information
696,047
<p>I'm writing a module and want to have a unified exception hierarchy for the exceptions that it can raise (e.g. inheriting from a <code>FooError</code> abstract class for all the <code>foo</code> module's specific exceptions). This allows users of the module to catch those particular exceptions and handle them distin...
41
2009-03-30T05:04:34Z
696,095
<p>You can use sys.exc_info() to get the traceback, and raise your new exception with said traceback (as the PEP mentions). If you want to preserve the old type and message, you can do so on the exception, but that's only useful if whatever catches your exception looks for it.</p> <p>For example</p> <pre><code>import...
21
2009-03-30T05:40:08Z
[ "python", "exception-handling", "polymorphism" ]
Re-raise exception with a different type and message, preserving existing information
696,047
<p>I'm writing a module and want to have a unified exception hierarchy for the exceptions that it can raise (e.g. inheriting from a <code>FooError</code> abstract class for all the <code>foo</code> module's specific exceptions). This allows users of the module to catch those particular exceptions and handle them distin...
41
2009-03-30T05:04:34Z
792,163
<p><strong>Python 3</strong> introduced <strong>exception chaining</strong> (as described in <a href="http://www.python.org/dev/peps/pep-3134/">PEP 3134</a>). This allows raising an exception, citing an existing exception as the “cause”:</p> <pre class="lang-python prettyprint-override"><code>try: frobnicate()...
38
2009-04-27T03:25:42Z
[ "python", "exception-handling", "polymorphism" ]
Re-raise exception with a different type and message, preserving existing information
696,047
<p>I'm writing a module and want to have a unified exception hierarchy for the exceptions that it can raise (e.g. inheriting from a <code>FooError</code> abstract class for all the <code>foo</code> module's specific exceptions). This allows users of the module to catch those particular exceptions and handle them distin...
41
2009-03-30T05:04:34Z
34,341,375
<p>The most straighforward solution to your needs should be this:</p> <pre><code>try: upload(file_id) except Exception as upload_error: error_msg = "Your upload failed! File: " + file_id raise RuntimeError(error_msg, upload_error) </code></pre> <p>In this way you can later print your message and the sp...
-1
2015-12-17T18:06:56Z
[ "python", "exception-handling", "polymorphism" ]
Python 2.6 on Windows: how to terminate subprocess.Popen with "shell=True" argument?
696,345
<p>Is there a way to terminate a process started with the subprocess.Popen class with the "shell" argument set to "True"? In the working minimal example below (uses wxPython) you can open and terminate a Notepad process happily, however if you change the Popen "shell" argument to "True" then the Notepad process doesn'...
7
2009-03-30T07:56:27Z
696,454
<p>When using shell=True and calling terminate on the process, you are actually killing the shell, not the notepad process. The shell would be whatever is specified in the COMSPEC environment variable.</p> <p>The only way I can think of killing this notepad process would be to use Win32process.EnumProcesses() to sear...
5
2009-03-30T08:46:54Z
[ "python", "windows", "windows-xp", "subprocess", "python-2.6" ]
Python 2.6 on Windows: how to terminate subprocess.Popen with "shell=True" argument?
696,345
<p>Is there a way to terminate a process started with the subprocess.Popen class with the "shell" argument set to "True"? In the working minimal example below (uses wxPython) you can open and terminate a Notepad process happily, however if you change the Popen "shell" argument to "True" then the Notepad process doesn'...
7
2009-03-30T07:56:27Z
696,674
<p>Python 2.6 has a kill method for subprocess.Popen objects. </p> <p><a href="http://docs.python.org/library/subprocess.html#subprocess.Popen.kill" rel="nofollow">http://docs.python.org/library/subprocess.html#subprocess.Popen.kill</a></p>
-1
2009-03-30T10:16:37Z
[ "python", "windows", "windows-xp", "subprocess", "python-2.6" ]
Python 2.6 on Windows: how to terminate subprocess.Popen with "shell=True" argument?
696,345
<p>Is there a way to terminate a process started with the subprocess.Popen class with the "shell" argument set to "True"? In the working minimal example below (uses wxPython) you can open and terminate a Notepad process happily, however if you change the Popen "shell" argument to "True" then the Notepad process doesn'...
7
2009-03-30T07:56:27Z
696,838
<p>Why are you using <code>shell=True</code>?</p> <p>Just don't do it. You don't need it, it invokes the shell and that is useless.</p> <p>I don't accept it has to be <code>True</code>, because it doesn't. Using <code>shell=True</code> only brings you problems and no benefit. Just avoid it at all costs. Unless you're...
8
2009-03-30T11:26:52Z
[ "python", "windows", "windows-xp", "subprocess", "python-2.6" ]
Python 2.6 on Windows: how to terminate subprocess.Popen with "shell=True" argument?
696,345
<p>Is there a way to terminate a process started with the subprocess.Popen class with the "shell" argument set to "True"? In the working minimal example below (uses wxPython) you can open and terminate a Notepad process happily, however if you change the Popen "shell" argument to "True" then the Notepad process doesn'...
7
2009-03-30T07:56:27Z
698,697
<p>Based on the tip given in Thomas Watnedal's answer, where he points out that just the shell is actually being killed in the example, I have arranged the following function which solves the problem for my scenario, based on the example given in Mark Hammond's PyWin32 library:</p> <p>procname is the name of the proce...
2
2009-03-30T19:35:58Z
[ "python", "windows", "windows-xp", "subprocess", "python-2.6" ]
Python 2.6 on Windows: how to terminate subprocess.Popen with "shell=True" argument?
696,345
<p>Is there a way to terminate a process started with the subprocess.Popen class with the "shell" argument set to "True"? In the working minimal example below (uses wxPython) you can open and terminate a Notepad process happily, however if you change the Popen "shell" argument to "True" then the Notepad process doesn'...
7
2009-03-30T07:56:27Z
20,824,104
<p>If you really need the <code>shell=True</code> flag, then the solution is to use the <code>start</code> shell command with the <code>/WAIT</code> flag. With this flag, the <code>start</code> process will wait for its child to terminate. Then, using for example the <a href="https://pypi.python.org/pypi?%3aaction=disp...
0
2013-12-29T10:18:28Z
[ "python", "windows", "windows-xp", "subprocess", "python-2.6" ]
What is the pythonic way to share common files in multiple projects?
696,792
<p>Lets say I have projects x and y in brother directories: projects/x and projects/y.<br /> There are some utility funcs common to both projects in myutils.py and some db stuff in mydbstuff.py, etc.<br /> Those are minor common goodies, so I don't want to create a single package for them. </p> <p>Questions arise abo...
4
2009-03-30T11:12:51Z
696,825
<p>The pythonic way is to create a single extra package for them.</p> <p>Why don't you want to create a package? You can distribute this package with both projects, and the effect would be the same.</p> <p>You'll never do it right for all instalation scenarios and platforms if you do it by mangling with PYTHONPATH an...
8
2009-03-30T11:24:34Z
[ "python" ]
What is the pythonic way to share common files in multiple projects?
696,792
<p>Lets say I have projects x and y in brother directories: projects/x and projects/y.<br /> There are some utility funcs common to both projects in myutils.py and some db stuff in mydbstuff.py, etc.<br /> Those are minor common goodies, so I don't want to create a single package for them. </p> <p>Questions arise abo...
4
2009-03-30T11:12:51Z
696,828
<p>You can add path to shared files to <a href="http://docs.python.org/library/sys.html#sys.path" rel="nofollow"><strong><code>sys.path</code></strong></a> either directly by <code>sys.path.append(pathToShared)</code> or by defining <code>.pth</code> files and add them to with <a href="http://docs.python.org/library/si...
1
2009-03-30T11:25:26Z
[ "python" ]
What is the pythonic way to share common files in multiple projects?
696,792
<p>Lets say I have projects x and y in brother directories: projects/x and projects/y.<br /> There are some utility funcs common to both projects in myutils.py and some db stuff in mydbstuff.py, etc.<br /> Those are minor common goodies, so I don't want to create a single package for them. </p> <p>Questions arise abo...
4
2009-03-30T11:12:51Z
697,020
<p>You can also create a <code>.pth</code> file, which will store the directory(ies) that you want added to your PYTHONPATH. <code>.pth</code> files are copied to the <code>Python/lib/site-packages</code> directory, and any directory in that file will be added to your PYTHONPATH at runtime.</p> <p><a href="http://doc...
0
2009-03-30T12:39:50Z
[ "python" ]
What is the pythonic way to share common files in multiple projects?
696,792
<p>Lets say I have projects x and y in brother directories: projects/x and projects/y.<br /> There are some utility funcs common to both projects in myutils.py and some db stuff in mydbstuff.py, etc.<br /> Those are minor common goodies, so I don't want to create a single package for them. </p> <p>Questions arise abo...
4
2009-03-30T11:12:51Z
697,052
<p>I agree with 'create a package'.</p> <p>If you cannot do that, how about using symbolic links/junctions (<code>ln -s</code> on Linux, <code>linkd</code> on Windows)?</p>
0
2009-03-30T12:50:06Z
[ "python" ]
What is the pythonic way to share common files in multiple projects?
696,792
<p>Lets say I have projects x and y in brother directories: projects/x and projects/y.<br /> There are some utility funcs common to both projects in myutils.py and some db stuff in mydbstuff.py, etc.<br /> Those are minor common goodies, so I don't want to create a single package for them. </p> <p>Questions arise abo...
4
2009-03-30T11:12:51Z
697,066
<p>I'd advise using <a href="http://peak.telecommunity.com/DevCenter/setuptools" rel="nofollow">setuptools</a> for this. It allows you to set dependencies so you can make sure all of these packages/individual modules are on the sys.path before installing a package. If you want to install something that's just a singl...
0
2009-03-30T12:54:36Z
[ "python" ]
Populate a list in python
696,874
<p>I have a series of Python tuples representing coordinates:</p> <pre><code>tuples = [(1,1), (0,1), (1,0), (0,0), (2,1)] </code></pre> <p>I want to create the following list:</p> <pre><code>l = [] for t in tuples: l[ t[0] ][ t[1] ] = something </code></pre> <p>I get an IndexError: list index out of range.</p> <...
4
2009-03-30T11:39:52Z
696,883
<p>You should look at dicts for something like that.</p> <pre><code>for t in tuples: if not l.has_key(t[0]): l[t[0]] = {} l[t[0]][t[1]] = something </code></pre> <p>Iterating over the dict is a bit different than iterating over a list, though. You'll have the keys(), values() and items() functions to help wit...
6
2009-03-30T11:45:52Z
[ "python", "list", "tuples" ]
Populate a list in python
696,874
<p>I have a series of Python tuples representing coordinates:</p> <pre><code>tuples = [(1,1), (0,1), (1,0), (0,0), (2,1)] </code></pre> <p>I want to create the following list:</p> <pre><code>l = [] for t in tuples: l[ t[0] ][ t[1] ] = something </code></pre> <p>I get an IndexError: list index out of range.</p> <...
4
2009-03-30T11:39:52Z
696,885
<p>No, you cannot create list with gaps. But you can create a dictionary with tuple keys:</p> <pre><code>tuples = [(1,1), (0,1), (1,0), (0,0), (2,1)] l = {} for t in tuples: l[t] = something </code></pre> <p><strong>Update:</strong> Try using <a href="http://numpy.scipy.org/" rel="nofollow">NumPy</a>, it provides...
8
2009-03-30T11:46:32Z
[ "python", "list", "tuples" ]
Populate a list in python
696,874
<p>I have a series of Python tuples representing coordinates:</p> <pre><code>tuples = [(1,1), (0,1), (1,0), (0,0), (2,1)] </code></pre> <p>I want to create the following list:</p> <pre><code>l = [] for t in tuples: l[ t[0] ][ t[1] ] = something </code></pre> <p>I get an IndexError: list index out of range.</p> <...
4
2009-03-30T11:39:52Z
696,889
<p>I think you have only declared a one dimensional list. </p> <p>I think you declare it as </p> <pre><code>l = [][] </code></pre> <p><hr /></p> <p><strong>Edit</strong>: That's a syntax error</p> <pre><code>&gt;&gt;&gt; l = [][] File "&lt;stdin&gt;", line 1 l = [][] ^ SyntaxError: invalid syntax ...
-2
2009-03-30T11:47:47Z
[ "python", "list", "tuples" ]
Populate a list in python
696,874
<p>I have a series of Python tuples representing coordinates:</p> <pre><code>tuples = [(1,1), (0,1), (1,0), (0,0), (2,1)] </code></pre> <p>I want to create the following list:</p> <pre><code>l = [] for t in tuples: l[ t[0] ][ t[1] ] = something </code></pre> <p>I get an IndexError: list index out of range.</p> <...
4
2009-03-30T11:39:52Z
696,896
<p>As mentioned earlier, you can't make lists with gaps, and dictionaries may be the better choice here. The trick is to makes sure that <code>l[t[0]]</code> exists when you put something in position <code>t[1]</code>. For this, I'd use a <a href="http://docs.python.org/library/collections.html#collections.defaultdict:...
0
2009-03-30T11:51:00Z
[ "python", "list", "tuples" ]
Populate a list in python
696,874
<p>I have a series of Python tuples representing coordinates:</p> <pre><code>tuples = [(1,1), (0,1), (1,0), (0,0), (2,1)] </code></pre> <p>I want to create the following list:</p> <pre><code>l = [] for t in tuples: l[ t[0] ][ t[1] ] = something </code></pre> <p>I get an IndexError: list index out of range.</p> <...
4
2009-03-30T11:39:52Z
696,897
<p>You create a one-dimensional list <code>l</code> and want to use it as a two-dimensional list. Thats why you get an index error.</p> <p>You have the following options: create a map and use the tuple t as index:</p> <pre><code>l = {} l[t] = something </code></pre> <p>and you will get entries in l as:</p> <pre><co...
3
2009-03-30T11:51:14Z
[ "python", "list", "tuples" ]
Populate a list in python
696,874
<p>I have a series of Python tuples representing coordinates:</p> <pre><code>tuples = [(1,1), (0,1), (1,0), (0,0), (2,1)] </code></pre> <p>I want to create the following list:</p> <pre><code>l = [] for t in tuples: l[ t[0] ][ t[1] ] = something </code></pre> <p>I get an IndexError: list index out of range.</p> <...
4
2009-03-30T11:39:52Z
696,925
<p>If you know the size that you before hand,you can make a list of lists like this</p> <pre><code>&gt;&gt;&gt; x = 3 &gt;&gt;&gt; y = 3 &gt;&gt;&gt; l = [[None] * x for i in range(y)] &gt;&gt;&gt; l [[None, None, None], [None, None, None], [None, None, None]] </code></pre> <p>Which you can then iterate like you orig...
2
2009-03-30T12:03:53Z
[ "python", "list", "tuples" ]
Populate a list in python
696,874
<p>I have a series of Python tuples representing coordinates:</p> <pre><code>tuples = [(1,1), (0,1), (1,0), (0,0), (2,1)] </code></pre> <p>I want to create the following list:</p> <pre><code>l = [] for t in tuples: l[ t[0] ][ t[1] ] = something </code></pre> <p>I get an IndexError: list index out of range.</p> <...
4
2009-03-30T11:39:52Z
696,946
<p>Extending the <a href="http://stackoverflow.com/questions/696874/populate-a-list-in-python/696925#696925">Nathan</a>'s answer, </p> <pre><code>tuples = [(1,1), (0,1), (1,0), (0,0), (2,1)] x = max(tuples, key = lambda z : z[0])[0] + 1 y = max(tuples, key = lambda z : z[1])[1] + 1 l = [[None] * y for i in range(x)] <...
1
2009-03-30T12:10:48Z
[ "python", "list", "tuples" ]
Populate a list in python
696,874
<p>I have a series of Python tuples representing coordinates:</p> <pre><code>tuples = [(1,1), (0,1), (1,0), (0,0), (2,1)] </code></pre> <p>I want to create the following list:</p> <pre><code>l = [] for t in tuples: l[ t[0] ][ t[1] ] = something </code></pre> <p>I get an IndexError: list index out of range.</p> <...
4
2009-03-30T11:39:52Z
697,000
<p>What do you mean exactly by "but as far as I know dictionaries cannot be sorted by keys"?</p> <p>While this is not strictly the same as a "sorted dictionary", you <em>can</em> easily turn a dictionary into a list, sorted by the key, which seems to be what you're after:</p> <pre><code>&gt;&gt;&gt; tuples = [(1,1), ...
1
2009-03-30T12:33:12Z
[ "python", "list", "tuples" ]
Populate a list in python
696,874
<p>I have a series of Python tuples representing coordinates:</p> <pre><code>tuples = [(1,1), (0,1), (1,0), (0,0), (2,1)] </code></pre> <p>I want to create the following list:</p> <pre><code>l = [] for t in tuples: l[ t[0] ][ t[1] ] = something </code></pre> <p>I get an IndexError: list index out of range.</p> <...
4
2009-03-30T11:39:52Z
697,013
<p>The dict solutions given are probably best for most purposes. For your issue of iterating over the keys in order, generally you would instead iterate over the <em>coordinate space</em>, not the dict keys, exactly the same way you would have for your list of lists. Use .get and you can specify the default value to ...
0
2009-03-30T12:38:32Z
[ "python", "list", "tuples" ]
How to set the crypto key for Python's MD5 module?
697,134
<p>What is the Python equivalent of following Perl code?</p> <pre><code>hmac_md5_hex($login . "^" . $seq . "^" . $time . "^" . $amo . "^", $CryptoKey); </code></pre> <p>The Python hashlib.md5 doesn't seem to take an "cryptographic key" argument. It only accepts 1 argument.</p>
0
2009-03-30T13:11:35Z
697,146
<p>You have to use the <a href="http://docs.python.org/library/hmac.html">hmac module</a> together with md5 or sha. Per default it uses md5:</p> <pre><code>In [1]: import hmac, hashlib In [2]: hmac.new('key', 'msg').hexdigest() Out[2]: '18e3548c59ad40dd03907b7aeee71d67' In [3]: hmac.new('key2', 'msg').hexdigest() Out[...
11
2009-03-30T13:16:13Z
[ "python", "hash", "md5", "hmac" ]
How to set the crypto key for Python's MD5 module?
697,134
<p>What is the Python equivalent of following Perl code?</p> <pre><code>hmac_md5_hex($login . "^" . $seq . "^" . $time . "^" . $amo . "^", $CryptoKey); </code></pre> <p>The Python hashlib.md5 doesn't seem to take an "cryptographic key" argument. It only accepts 1 argument.</p>
0
2009-03-30T13:11:35Z
697,157
<p>Take a look at <a href="http://docs.python.org/library/hmac.html" rel="nofollow">this python library documentation about hmac</a></p> <p>What you probably want is:</p> <pre><code>import hmac hmac_object = hmac.new(crypto_key) hmac_object.update('^'.join([login, seq, time, amo, '']) print hmac_object.hexdigest() </...
3
2009-03-30T13:19:21Z
[ "python", "hash", "md5", "hmac" ]
How to set the crypto key for Python's MD5 module?
697,134
<p>What is the Python equivalent of following Perl code?</p> <pre><code>hmac_md5_hex($login . "^" . $seq . "^" . $time . "^" . $amo . "^", $CryptoKey); </code></pre> <p>The Python hashlib.md5 doesn't seem to take an "cryptographic key" argument. It only accepts 1 argument.</p>
0
2009-03-30T13:11:35Z
9,518,787
<p>Another solution, based on <a href="https://www.dlitz.net/software/pycrypto/" rel="nofollow">PyCrypto</a>:</p> <pre><code>from Crypto.Hash import HMAC print HMAC.new(CryptoKey, '^'.join([login, seq, time, amo, ''])).hexdigest() </code></pre>
0
2012-03-01T15:19:54Z
[ "python", "hash", "md5", "hmac" ]
How do I configure Eclipse to launch a browser when Run or Debug is selected using Pydev plugin
697,142
<p>I'm learning Python and Django using the Eclipse Pydev plugin. I want the internal or external browser to launch or refresh with the URL http:/127.0.0.1 when I press Run or Debug. I've seen it done with the PHP plugins but not Pydev.</p>
13
2009-03-30T13:14:05Z
698,968
<p>project properties (right click project in left pane)</p> <p>Go to "run/debug settings", add a new profile. Setup the path and environment etc... you want to launch. The new configuration will show up in your build menu. You could also configure it as an "external tool"</p>
1
2009-03-30T20:53:11Z
[ "python", "eclipse", "eclipse-plugin", "pydev" ]
How do I configure Eclipse to launch a browser when Run or Debug is selected using Pydev plugin
697,142
<p>I'm learning Python and Django using the Eclipse Pydev plugin. I want the internal or external browser to launch or refresh with the URL http:/127.0.0.1 when I press Run or Debug. I've seen it done with the PHP plugins but not Pydev.</p>
13
2009-03-30T13:14:05Z
1,182,231
<p>Here are the steps to set up an external launch configuration to launch IE:</p> <ol> <li>Select <strong>Run</strong>-><strong>External Tools</strong>-><strong>External Tools Configurations...</strong></li> <li>In the left hand pane, select <strong>Program</strong> then the new icon (left-most icon above the pane).<...
7
2009-07-25T14:50:33Z
[ "python", "eclipse", "eclipse-plugin", "pydev" ]
Importing in Python
697,281
<p>In Python 2.5, I import modules by changing environment variables. It works, but using site-packages does not. Is there another way to import modules in directories other than C:\Python25 ?</p>
2
2009-03-30T13:46:55Z
697,299
<p>Append the location to the module to <code>sys.path</code>. </p> <p>Edit: (to counter the post below ;-) ) <code>os.path</code> does something completely different. You need to use <code>sys.path</code>.</p> <pre><code>sys.path.append("/home/me/local/modules") </code></pre>
4
2009-03-30T13:52:52Z
[ "python", "import" ]
Importing in Python
697,281
<p>In Python 2.5, I import modules by changing environment variables. It works, but using site-packages does not. Is there another way to import modules in directories other than C:\Python25 ?</p>
2
2009-03-30T13:46:55Z
697,300
<p><code>sys.path</code> is a list to which you can append custom paths to search like this:</p> <pre><code>sys.path.append("/home/foo") </code></pre>
0
2009-03-30T13:53:05Z
[ "python", "import" ]
Importing in Python
697,281
<p>In Python 2.5, I import modules by changing environment variables. It works, but using site-packages does not. Is there another way to import modules in directories other than C:\Python25 ?</p>
2
2009-03-30T13:46:55Z
697,337
<p>Directories added to the <code>PYTHONPATH</code> environment variable are searched after <code>site-packages</code>, so if you have a module in <code>site-packages</code> with the same name as the module you want from your <code>PYTHONPATH</code>, the <code>site-packages</code> version will win. Also, you may need t...
5
2009-03-30T14:01:08Z
[ "python", "import" ]
Importing in Python
697,281
<p>In Python 2.5, I import modules by changing environment variables. It works, but using site-packages does not. Is there another way to import modules in directories other than C:\Python25 ?</p>
2
2009-03-30T13:46:55Z
697,693
<p>On way is with <a href="http://docs.python.org/using/cmdline.html#envvar-PYTHONPATH"><strong><code>PYTHONPATH</code></strong></a> environment variable. Other one is to add path to <a href="http://docs.python.org/library/sys.html#sys.path"><strong><code>sys.path</code></strong></a> either directly by <strong><code>sy...
7
2009-03-30T15:26:43Z
[ "python", "import" ]
How do I get the filepath for a class in Python?
697,320
<p>Given a class C in Python, how can I determine which file the class was defined in? I need something that can work from either the class C, or from an instance off C.</p> <p>The reason I am doing this, is because I am generally a fan off putting files that belong together in the same folder. I want to create a clas...
40
2009-03-30T13:58:59Z
697,356
<p>try:</p> <pre><code>import sys, os os.path.abspath(sys.modules[LocationArtifact.__module__].__file__) </code></pre>
19
2009-03-30T14:05:42Z
[ "python", "class", "introspection" ]
How do I get the filepath for a class in Python?
697,320
<p>Given a class C in Python, how can I determine which file the class was defined in? I need something that can work from either the class C, or from an instance off C.</p> <p>The reason I am doing this, is because I am generally a fan off putting files that belong together in the same folder. I want to create a clas...
40
2009-03-30T13:58:59Z
697,395
<p>You can use the <a href="http://docs.python.org/library/inspect.html#inspect.getfile">inspect</a> module, like this:</p> <pre><code>import inspect inspect.getfile(C.__class__) </code></pre>
57
2009-03-30T14:14:55Z
[ "python", "class", "introspection" ]
How do I get the filepath for a class in Python?
697,320
<p>Given a class C in Python, how can I determine which file the class was defined in? I need something that can work from either the class C, or from an instance off C.</p> <p>The reason I am doing this, is because I am generally a fan off putting files that belong together in the same folder. I want to create a clas...
40
2009-03-30T13:58:59Z
697,405
<p>This is the wrong approach for Django and really forcing things.</p> <p>The typical Django app pattern is:</p> <ul> <li><strong>/project</strong> <ul> <li><strong>/appname</strong> <ul> <li>models.py</li> <li>views.py</li> <li><strong>/templates</strong> <ul> <li>index.html</li> <li>etc.</li> </ul></li> </ul></li>...
4
2009-03-30T14:17:09Z
[ "python", "class", "introspection" ]
How to integrate BIRT with Python
697,594
<p>Has anyone ever tried that?</p>
3
2009-03-30T15:05:01Z
716,222
<p>What kind of integration are you talking about?</p> <p>If you want to call some BIRT API the I gues it could be done from Jython as Jython can call any Java API.</p> <p>If you don't need to call the BIRT API then you can just get the birt reports with http requests from the BIRT report server (a tomcat application...
1
2009-04-04T01:00:17Z
[ "java", "python", "reporting", "birt" ]
How to integrate BIRT with Python
697,594
<p>Has anyone ever tried that?</p>
3
2009-03-30T15:05:01Z
6,265,734
<p>A similar question was asked about integrating with xulrunner applications. Apparently there is a commandline version that can be used:</p> <p><a href="http://stackoverflow.com/questions/169512/what-is-the-simplest-way-to-set-up-a-birt-report-viewer-for-a-xulrunner-applicati">What is the simplest way to set up a BI...
1
2011-06-07T13:14:18Z
[ "java", "python", "reporting", "birt" ]
Processing XML into MySQL in good form
697,741
<p>I need to process XML documents of varying formats into records in a MySQL database on a daily basis. The data I need from each XML document is interspersed with a good deal of data I don't need, and each document's node names are different. For example:</p> <p>source #1:</p> <pre><code>&lt;object id="1"&gt; ...
0
2009-03-30T15:38:06Z
697,794
<p>Using XSLT is an overkill. I like approach (2), it makes a lot of sense.</p> <p>Using Python I'd try to make a class for every document type. The class would inherit from dict and on its <code>__init__</code> parse the given document and populate itself with the 'id', 'interval' and 'url'.</p> <p>Then the code in ...
2
2009-03-30T15:54:49Z
[ "python", "xml", "xslt", "parsing" ]
Processing XML into MySQL in good form
697,741
<p>I need to process XML documents of varying formats into records in a MySQL database on a daily basis. The data I need from each XML document is interspersed with a good deal of data I don't need, and each document's node names are different. For example:</p> <p>source #1:</p> <pre><code>&lt;object id="1"&gt; ...
0
2009-03-30T15:38:06Z
697,798
<p>I've been successfully using variant the third approach. But documents I've been processing were a lot bigger. If it's a overkill or not, well that really depends how fluent you are with XSLT.</p>
0
2009-03-30T15:55:56Z
[ "python", "xml", "xslt", "parsing" ]
Processing XML into MySQL in good form
697,741
<p>I need to process XML documents of varying formats into records in a MySQL database on a daily basis. The data I need from each XML document is interspersed with a good deal of data I don't need, and each document's node names are different. For example:</p> <p>source #1:</p> <pre><code>&lt;object id="1"&gt; ...
0
2009-03-30T15:38:06Z
698,040
<p>If your various input formats are unambiguous, you can do this:</p> <pre><code>&lt;xsl:template match="object"&gt; &lt;object&gt; &lt;id&gt;&lt;xsl:value-of select="@id | objectid" /&gt;&lt;/id&gt; &lt;title&gt;&lt;xsl:value-of select="title | thetitle" /&gt;&lt;/title&gt; &lt;url&gt;&lt;xsl:value-of ...
0
2009-03-30T16:46:54Z
[ "python", "xml", "xslt", "parsing" ]
Is it possible to split a SWIG module for compilation, but rejoin it when linking?
697,749
<p>I hit this issue about two years ago when I first implemented our SWIG bindings. As soon as we exposed a large amount of code we got to the point where SWIG would output C++ files so large the compiler could not handle them. The only way I could get around the issue was to split up the interfaces into multiple mod...
7
2009-03-30T15:40:18Z
698,089
<p>If split properly, the modules don't necessarily need to have the same dependencies as the others - just what's necessary to do compilation. If you break things up appropriately, you can have libraries without cyclic dependencies. The issue with using multiple libraries is that by default, SWIG declares its runtim...
0
2009-03-30T16:59:19Z
[ "c++", "python", "swig" ]
abstracting the conversion between id3 tags, m4a tags, flac tags
697,776
<p>I'm looking for a resource in python or bash that will make it easy to take, for example, mp3 file X and m4a file Y and say "copy X's tags to Y".</p> <p>Python's "mutagen" module is great for manupulating tags in general, but there's no abstract concept of "artist field" that spans different types of tag; I want a ...
13
2009-03-30T15:49:59Z
698,252
<p>You can just write a simple app with a mapping of each tag name in each format to an "abstract tag" type, and then its easy to convert from one to the other. You don't even have to know all available types - just those that you are interested in.</p> <p>Seems to me like a weekend-project type of time investment, po...
0
2009-03-30T17:42:59Z
[ "python", "bash", "mp3", "m4a" ]
abstracting the conversion between id3 tags, m4a tags, flac tags
697,776
<p>I'm looking for a resource in python or bash that will make it easy to take, for example, mp3 file X and m4a file Y and say "copy X's tags to Y".</p> <p>Python's "mutagen" module is great for manupulating tags in general, but there's no abstract concept of "artist field" that spans different types of tag; I want a ...
13
2009-03-30T15:49:59Z
699,218
<p>I needed this exact thing, and I, too, realized quickly that mutagen is not a distant enough abstraction to do this kind of thing. Fortunately, the authors of mutagen needed it for their media player <a href="http://code.google.com/p/quodlibet/" rel="nofollow">QuodLibet</a>.</p> <p>I had to dig through the QuodLibe...
8
2009-03-30T22:04:09Z
[ "python", "bash", "mp3", "m4a" ]
abstracting the conversion between id3 tags, m4a tags, flac tags
697,776
<p>I'm looking for a resource in python or bash that will make it easy to take, for example, mp3 file X and m4a file Y and say "copy X's tags to Y".</p> <p>Python's "mutagen" module is great for manupulating tags in general, but there's no abstract concept of "artist field" that spans different types of tag; I want a ...
13
2009-03-30T15:49:59Z
740,815
<p>There's also tagpy, which seems to work well.</p>
0
2009-04-11T21:38:10Z
[ "python", "bash", "mp3", "m4a" ]
abstracting the conversion between id3 tags, m4a tags, flac tags
697,776
<p>I'm looking for a resource in python or bash that will make it easy to take, for example, mp3 file X and m4a file Y and say "copy X's tags to Y".</p> <p>Python's "mutagen" module is great for manupulating tags in general, but there's no abstract concept of "artist field" that spans different types of tag; I want a ...
13
2009-03-30T15:49:59Z
1,665,810
<p>Here's some example code, a script that I wrote to copy tags between files using Quod Libet's music format classes (not mutagen's!). To run it, just do <code>copytags.py src1 dest1 src2 dest2 src3 dest3</code>, and it will copy the tags in sec1 to dest1 (after deleting any existing tags on dest1!), and so on. Note t...
2
2009-11-03T07:42:52Z
[ "python", "bash", "mp3", "m4a" ]
abstracting the conversion between id3 tags, m4a tags, flac tags
697,776
<p>I'm looking for a resource in python or bash that will make it easy to take, for example, mp3 file X and m4a file Y and say "copy X's tags to Y".</p> <p>Python's "mutagen" module is great for manupulating tags in general, but there's no abstract concept of "artist field" that spans different types of tag; I want a ...
13
2009-03-30T15:49:59Z
7,084,947
<p>I have a bash script that does exactly that, <a href="https://gist.github.com/1150146" rel="nofollow">atwat-tagger</a>. It supports flac, mp3, ogg and mp4 files.</p> <pre><code>usage: `atwat-tagger.sh inputfile.mp3 outputfile.ogg` </code></pre> <p>I know your project is already finished, but somebody who finds thi...
2
2011-08-16T21:00:29Z
[ "python", "bash", "mp3", "m4a" ]
Dilemma: Should I learn Seaside or a Python framework?
697,866
<p>I know it's kinda subjective but, if you were to put yourself in my shoes <strong>which would you invest the time in learning?</strong></p> <p>I want to write a web app which deals securely with relatively modest amounts of peoples private data, a few thousand records of a few Kb each but stuff that needs to be kep...
9
2009-03-30T16:11:14Z
697,911
<p>While considering a Smalltalk web framework, look at <a href="http://www.aidaweb.si" rel="nofollow">Aida/Web</a> as well. Aida has built-in security with user/group/role management and strong access control, which can help you a lot in your case. That way you can achieve safe enough separation of users at the user l...
4
2009-03-30T16:21:45Z
[ "python", "frameworks", "seaside" ]
Dilemma: Should I learn Seaside or a Python framework?
697,866
<p>I know it's kinda subjective but, if you were to put yourself in my shoes <strong>which would you invest the time in learning?</strong></p> <p>I want to write a web app which deals securely with relatively modest amounts of peoples private data, a few thousand records of a few Kb each but stuff that needs to be kep...
9
2009-03-30T16:11:14Z
697,920
<p>I'd say take a look at <a href="http://www.djangoproject.com" rel="nofollow">Django</a>. It's a Python framework with a ready-made authentication system that's independent of the hosting OS, which means that compromises are limited to the app that was compromised (barring some exploit against the web server hosting ...
8
2009-03-30T16:23:23Z
[ "python", "frameworks", "seaside" ]
Dilemma: Should I learn Seaside or a Python framework?
697,866
<p>I know it's kinda subjective but, if you were to put yourself in my shoes <strong>which would you invest the time in learning?</strong></p> <p>I want to write a web app which deals securely with relatively modest amounts of peoples private data, a few thousand records of a few Kb each but stuff that needs to be kep...
9
2009-03-30T16:11:14Z
697,934
<p>I think you've pretty much summed up the pros and cons. Seaside isn't <em>that</em> hard to set up (I've installed it twice for various projects) but using it will definitely affect how you work--in addition to re-learning the language you'll probably have to adjust lots of assumptions about your work flow. </p> ...
1
2009-03-30T16:25:41Z
[ "python", "frameworks", "seaside" ]
Dilemma: Should I learn Seaside or a Python framework?
697,866
<p>I know it's kinda subjective but, if you were to put yourself in my shoes <strong>which would you invest the time in learning?</strong></p> <p>I want to write a web app which deals securely with relatively modest amounts of peoples private data, a few thousand records of a few Kb each but stuff that needs to be kep...
9
2009-03-30T16:11:14Z
697,940
<p>Forget about mod_python, there is <a href="http://www.python.org/dev/peps/pep-0333/" rel="nofollow">WSGI</a>. </p> <p>I'd recommend <a href="http://www.djangoproject.com/" rel="nofollow">Django</a>. It runs on any <a href="http://www.python.org/dev/peps/pep-0333/" rel="nofollow">WSGI</a> server, there are a lot to ...
10
2009-03-30T16:26:44Z
[ "python", "frameworks", "seaside" ]
Dilemma: Should I learn Seaside or a Python framework?
697,866
<p>I know it's kinda subjective but, if you were to put yourself in my shoes <strong>which would you invest the time in learning?</strong></p> <p>I want to write a web app which deals securely with relatively modest amounts of peoples private data, a few thousand records of a few Kb each but stuff that needs to be kep...
9
2009-03-30T16:11:14Z
698,677
<p>Disclaimer: I really don't like PHP, Python is nice, but doesn't come close to Smalltalk in my book. But I am a biased Smalltalker. Some answers about Seaside/Squeak:</p> <p>Q: Which I guess runs on a squeak app server?</p> <p>Seaside runs in several different Smalltalks (VW, Gemstone, Squeak etc). The term "app s...
10
2009-03-30T19:28:25Z
[ "python", "frameworks", "seaside" ]
Dilemma: Should I learn Seaside or a Python framework?
697,866
<p>I know it's kinda subjective but, if you were to put yourself in my shoes <strong>which would you invest the time in learning?</strong></p> <p>I want to write a web app which deals securely with relatively modest amounts of peoples private data, a few thousand records of a few Kb each but stuff that needs to be kep...
9
2009-03-30T16:11:14Z
698,940
<p>I've been getting into seaside myself but in many ways it is very hard to get started, which has nothing to do with the smalltalk which can be picked up extremely quickly. The challenge is that you are really protected from writing html directly. </p> <p>I find in most frameworks when you get stuck on how to do s...
6
2009-03-30T20:47:44Z
[ "python", "frameworks", "seaside" ]
Dilemma: Should I learn Seaside or a Python framework?
697,866
<p>I know it's kinda subjective but, if you were to put yourself in my shoes <strong>which would you invest the time in learning?</strong></p> <p>I want to write a web app which deals securely with relatively modest amounts of peoples private data, a few thousand records of a few Kb each but stuff that needs to be kep...
9
2009-03-30T16:11:14Z
776,464
<p>Have you taken a look at <strong>www.nagare.org</strong> ?</p> <p>A framework particularly for web apps rather than web sites.</p> <p>It is based around the Seaside concepts but you program in Python (nagare deploys a distribution of python called Stackless Python to get the continuations working).</p> <p>Like Se...
5
2009-04-22T09:59:02Z
[ "python", "frameworks", "seaside" ]
Dilemma: Should I learn Seaside or a Python framework?
697,866
<p>I know it's kinda subjective but, if you were to put yourself in my shoes <strong>which would you invest the time in learning?</strong></p> <p>I want to write a web app which deals securely with relatively modest amounts of peoples private data, a few thousand records of a few Kb each but stuff that needs to be kep...
9
2009-03-30T16:11:14Z
869,218
<p>I'm toying with Seaside myself and found <a href="http://seaside.gemstone.com/tutorial.html" rel="nofollow">this tutorial</a> to be invaluable in gaining insight into the capabilities of the framework.</p>
3
2009-05-15T15:04:25Z
[ "python", "frameworks", "seaside" ]
Dilemma: Should I learn Seaside or a Python framework?
697,866
<p>I know it's kinda subjective but, if you were to put yourself in my shoes <strong>which would you invest the time in learning?</strong></p> <p>I want to write a web app which deals securely with relatively modest amounts of peoples private data, a few thousand records of a few Kb each but stuff that needs to be kep...
9
2009-03-30T16:11:14Z
3,197,051
<p>There is now an <a href="http://book.seaside.st/book" rel="nofollow">online book on Seaside</a> to complete the <a href="http://seaside.gemstone.com/tutorial.html" rel="nofollow">tutorial pointed out earlier</a>.</p>
1
2010-07-07T16:55:01Z
[ "python", "frameworks", "seaside" ]
How to send a session message to an anonymous user in a Django site?
697,902
<p>I often show messages about user actions to logged in users in my Django app views using:</p> <pre><code>request.user.message_set.create("message to user") </code></pre> <p>How could I do the same for anonymous (not logged in) users? There is no request.user for anonymous users, but the Django documentation says ...
5
2009-03-30T16:19:00Z
698,045
<p>Store the data directly in the session, which is a dict-like object. Then in the view/template, check for the value.</p> <p>More information here:</p> <p><a href="http://docs.djangoproject.com/en/dev/topics/http/sessions/#using-sessions-in-views" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/http/ses...
4
2009-03-30T16:48:33Z
[ "python", "django", "session", "django-views" ]
How to send a session message to an anonymous user in a Django site?
697,902
<p>I often show messages about user actions to logged in users in my Django app views using:</p> <pre><code>request.user.message_set.create("message to user") </code></pre> <p>How could I do the same for anonymous (not logged in) users? There is no request.user for anonymous users, but the Django documentation says ...
5
2009-03-30T16:19:00Z
698,934
<p>This is what I do, using context processors:</p> <p><code>project/application/context.py</code> (check for messages and add them to the context):</p> <pre><code>def messages(request): messages = {} if 'message' in request.session: message_type = request.session.get('message_type', 'error') ...
7
2009-03-30T20:45:38Z
[ "python", "django", "session", "django-views" ]
How to send a session message to an anonymous user in a Django site?
697,902
<p>I often show messages about user actions to logged in users in my Django app views using:</p> <pre><code>request.user.message_set.create("message to user") </code></pre> <p>How could I do the same for anonymous (not logged in) users? There is no request.user for anonymous users, but the Django documentation says ...
5
2009-03-30T16:19:00Z
704,661
<p>See <a href="http://code.google.com/p/django-session-messages/" rel="nofollow">http://code.google.com/p/django-session-messages/</a> until the patch that enables session based messages lands in Django tree (as I saw recently, it's marked for 1.2, so no hope for quick addition...).</p> <p>Another project with simila...
4
2009-04-01T08:56:30Z
[ "python", "django", "session", "django-views" ]
Easy way to parse .h file for comments using Python?
697,945
<p>How to parse in easy way a <strong>.h</strong> file written in <strong>C</strong> for <strong>comments</strong> and entity names using <strong>Python</strong>?</p> <p>We're suppose for a further writing the content into the word file already developed.</p> <p>Source comments are formatted using a simple tag-style ...
4
2009-03-30T16:27:45Z
697,969
<p>Perhaps <a href="http://docs.python.org/library/shlex.html" rel="nofollow">shlex module</a> would do?</p> <p>If not, there are some more powerful alternatives: <a href="http://wiki.python.org/moin/LanguageParsing" rel="nofollow">http://wiki.python.org/moin/LanguageParsing</a></p>
1
2009-03-30T16:34:05Z
[ "python", "parsing", "lexer" ]
Easy way to parse .h file for comments using Python?
697,945
<p>How to parse in easy way a <strong>.h</strong> file written in <strong>C</strong> for <strong>comments</strong> and entity names using <strong>Python</strong>?</p> <p>We're suppose for a further writing the content into the word file already developed.</p> <p>Source comments are formatted using a simple tag-style ...
4
2009-03-30T16:27:45Z
698,005
<p>This has already been done. Several times over.</p> <p>Here is a parser for the C language written in Python. Start with this.</p> <p><a href="http://wiki.python.org/moin/SeeGramWrap" rel="nofollow">http://wiki.python.org/moin/SeeGramWrap</a></p> <p>Other parsers.</p> <p><a href="http://wiki.python.org/moin/La...
4
2009-03-30T16:41:01Z
[ "python", "parsing", "lexer" ]
Easy way to parse .h file for comments using Python?
697,945
<p>How to parse in easy way a <strong>.h</strong> file written in <strong>C</strong> for <strong>comments</strong> and entity names using <strong>Python</strong>?</p> <p>We're suppose for a further writing the content into the word file already developed.</p> <p>Source comments are formatted using a simple tag-style ...
4
2009-03-30T16:27:45Z
698,121
<p>Here's a quick and dirty solution. It won't handle comments in strings, but since this is just for header files that shouldn't be an issue.</p> <pre>S_CODE,S_INLINE,S_MULTLINE = range (3) f = open (sys.argv[1]) state = S_CODE comments = '' i = iter (lambda: f.read (1), '') while True: try: c = i.next () ...
1
2009-03-30T17:10:54Z
[ "python", "parsing", "lexer" ]
How can I parse a time string containing milliseconds in it with python?
698,223
<p>I am able to parse strings containing date/time with <strong>time.strptime</strong></p> <pre><code>&gt;&gt;&gt; import time &gt;&gt;&gt; time.strptime('30/03/09 16:31:32', '%d/%m/%y %H:%M:%S') (2009, 3, 30, 16, 31, 32, 0, 89, -1) </code></pre> <p>How can I parse a time string that contains milliseconds?</p> <pre>...
110
2009-03-30T17:36:53Z
698,256
<p>My first thought was to try passing it '30/03/09 16:31:32.123' (with a period instead of a colon between the seconds and the milliseconds.) But that didn't work. A quick glance at the docs indicates that fractional seconds are ignored in any case...</p> <p>Ah, version differences. This was <a href="http://www.na...
1
2009-03-30T17:43:21Z
[ "python", "date", "time" ]
How can I parse a time string containing milliseconds in it with python?
698,223
<p>I am able to parse strings containing date/time with <strong>time.strptime</strong></p> <pre><code>&gt;&gt;&gt; import time &gt;&gt;&gt; time.strptime('30/03/09 16:31:32', '%d/%m/%y %H:%M:%S') (2009, 3, 30, 16, 31, 32, 0, 89, -1) </code></pre> <p>How can I parse a time string that contains milliseconds?</p> <pre>...
110
2009-03-30T17:36:53Z
698,257
<p>from python mailing lists: <a href="http://code.activestate.com/lists/python-list/521885/" rel="nofollow">parsing millisecond thread</a>. There is a function posted there that seems to get the job done, although as mentioned in the author's comments it is kind of a hack. It uses regular expressions to handle the e...
1
2009-03-30T17:43:24Z
[ "python", "date", "time" ]
How can I parse a time string containing milliseconds in it with python?
698,223
<p>I am able to parse strings containing date/time with <strong>time.strptime</strong></p> <pre><code>&gt;&gt;&gt; import time &gt;&gt;&gt; time.strptime('30/03/09 16:31:32', '%d/%m/%y %H:%M:%S') (2009, 3, 30, 16, 31, 32, 0, 89, -1) </code></pre> <p>How can I parse a time string that contains milliseconds?</p> <pre>...
110
2009-03-30T17:36:53Z
698,271
<p>To give the code that <a href="http://stackoverflow.com/questions/698223/how-can-i-parse-a-time-string-containing-milliseconds-in-it-with-python/698257#698257">nstehr's answer</a> refers to (from <a href="http://mail.python.org/pipermail/python-list/2006-June/562457.html" rel="nofollow">its source</a>):</p> <pre><c...
2
2009-03-30T17:48:23Z
[ "python", "date", "time" ]
How can I parse a time string containing milliseconds in it with python?
698,223
<p>I am able to parse strings containing date/time with <strong>time.strptime</strong></p> <pre><code>&gt;&gt;&gt; import time &gt;&gt;&gt; time.strptime('30/03/09 16:31:32', '%d/%m/%y %H:%M:%S') (2009, 3, 30, 16, 31, 32, 0, 89, -1) </code></pre> <p>How can I parse a time string that contains milliseconds?</p> <pre>...
110
2009-03-30T17:36:53Z
698,279
<p>Python 2.6 added a new strftime/strptime macro <code>%f</code>, which does microseconds. Not sure if this is documented anywhere. But if you're using 2.6 or 3.0, you can do this:</p> <pre><code>time.strptime('30/03/09 16:31:32.123', '%d/%m/%y %H:%M:%S.%f') </code></pre> <p>Edit: I never really work with the <cod...
160
2009-03-30T17:49:33Z
[ "python", "date", "time" ]
How can I parse a time string containing milliseconds in it with python?
698,223
<p>I am able to parse strings containing date/time with <strong>time.strptime</strong></p> <pre><code>&gt;&gt;&gt; import time &gt;&gt;&gt; time.strptime('30/03/09 16:31:32', '%d/%m/%y %H:%M:%S') (2009, 3, 30, 16, 31, 32, 0, 89, -1) </code></pre> <p>How can I parse a time string that contains milliseconds?</p> <pre>...
110
2009-03-30T17:36:53Z
3,916,106
<p>I know this is an older question but I'm still using Python 2.4.3 and I needed to find a better way of converting the string of data to a datetime.</p> <p>The solution if datetime doesn't support %f and without needing a try/except is:</p> <pre><code> (dt, mSecs) = row[5].strip().split(".") dt = datetime.d...
12
2010-10-12T15:09:19Z
[ "python", "date", "time" ]
How can I parse a time string containing milliseconds in it with python?
698,223
<p>I am able to parse strings containing date/time with <strong>time.strptime</strong></p> <pre><code>&gt;&gt;&gt; import time &gt;&gt;&gt; time.strptime('30/03/09 16:31:32', '%d/%m/%y %H:%M:%S') (2009, 3, 30, 16, 31, 32, 0, 89, -1) </code></pre> <p>How can I parse a time string that contains milliseconds?</p> <pre>...
110
2009-03-30T17:36:53Z
26,689,839
<p>For python 2 i did this</p> <pre><code>print ( time.strftime("%H:%M:%S", time.localtime(time.time())) + "." + str(time.time()).split(".",1)[1]) </code></pre> <p>it prints time "%H:%M:%S" , splits the time.time() to two substrings (before and after the .) xxxxxxx.xx and since .xx are my milliseconds i add the secon...
0
2014-11-01T13:36:53Z
[ "python", "date", "time" ]
Google App Engine Local Environment Error: "cannot import name webapp"
698,549
<p>I've built a GAE site on a Windows machine and I want to work on it from my MacBook. I have the code in SVN remotely and I installed the Mac version of GAE which comes with this launcher program. When I configured my application in the launcher and fire the application up, I get the following error:</p> <pre><cod...
0
2009-03-30T18:49:52Z
698,778
<p>Sounds like something went wrong with your Mac GAE install mate. I'm assuming you have Leopard installed. As the docs say, <a href="http://code.google.com/appengine/docs/python/gettingstarted/devenvironment.html" rel="nofollow">Leo comes with py2.5</a>, I'm again assuming you are using that. You may need to insta...
0
2009-03-30T19:57:35Z
[ "python", "google-app-engine" ]
Google App Engine Local Environment Error: "cannot import name webapp"
698,549
<p>I've built a GAE site on a Windows machine and I want to work on it from my MacBook. I have the code in SVN remotely and I installed the Mac version of GAE which comes with this launcher program. When I configured my application in the launcher and fire the application up, I get the following error:</p> <pre><cod...
0
2009-03-30T18:49:52Z
10,676,289
<p>I know this is a dead question, but I've recently had the same problem using <a href="https://django-nonrel.readthedocs.org/en/latest/content/djangoappengine%20-%20Django%20App%20Engine%20backends%20%28DB,%20email,%20etc.%29.html#file-uploads-downloads" rel="nofollow">django-nonrel</a>, that would let me put a djang...
0
2012-05-20T19:02:10Z
[ "python", "google-app-engine" ]
Python tkinter label won't change at beginning of function
698,707
<p>I'm using tkinter with Python to create a user interface for a program that converts Excel files to CSV.</p> <p>I created a label to act as a status bar, and set statusBarText as a StringVar() as the textvariable. inputFileEntry and outputFileEntry are textvariables that contain the input and output file paths.</p>...
2
2009-03-30T19:38:01Z
699,057
<p>How are you creating your Label? I have this little test setup:</p> <pre><code>from Tkinter import * class LabelTest: def __init__(self, master): self.test = StringVar() self.button = Button(master, text="Change Label", command=self.change) self.button.grid(row=0, column=0, sticky=W) ...
3
2009-03-30T21:14:34Z
[ "python", "function", "label", "tkinter", "statusbar" ]
Python tkinter label won't change at beginning of function
698,707
<p>I'm using tkinter with Python to create a user interface for a program that converts Excel files to CSV.</p> <p>I created a label to act as a status bar, and set statusBarText as a StringVar() as the textvariable. inputFileEntry and outputFileEntry are textvariables that contain the input and output file paths.</p>...
2
2009-03-30T19:38:01Z
699,069
<p>Since you're doing all of this in a single method call, the GUI never gets a chance to update before you start your sub process. Check out update_idletasks() call...</p> <p>from <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/universal.html">http://infohost.nmt.edu/tcc/help/pubs/tkinter/universal.html</a></p...
10
2009-03-30T21:16:58Z
[ "python", "function", "label", "tkinter", "statusbar" ]
Python: Do Python Lists keep a count for len() or does it count for each call?
699,177
<p>If I keep calling len() on a very long list, am I wasting time, or does it keep an int count in the background?</p>
35
2009-03-30T21:50:45Z
699,187
<p>It has to store the length somewhere, so you aren't counting the number of items every time.</p>
1
2009-03-30T21:53:30Z
[ "python" ]
Python: Do Python Lists keep a count for len() or does it count for each call?
699,177
<p>If I keep calling len() on a very long list, am I wasting time, or does it keep an int count in the background?</p>
35
2009-03-30T21:50:45Z
699,191
<p>Don't worry: Of course it saves the count and thus <code>len()</code> on lists is a pretty cheap operation. Same is true for strings, dictionaries and sets, by the way!</p>
41
2009-03-30T21:54:32Z
[ "python" ]
Python: Do Python Lists keep a count for len() or does it count for each call?
699,177
<p>If I keep calling len() on a very long list, am I wasting time, or does it keep an int count in the background?</p>
35
2009-03-30T21:50:45Z
699,192
<p>Write your program so that it's <strong>optimised for clarity and easily maintainable</strong>. Is your program clearer with a call to <code>len(foo)</code>? Then do that.</p> <p>Are you worried about the time taken? Use the <a href="https://docs.python.org/3/library/timeit" rel="nofollow"><code>timeit</code> modul...
9
2009-03-30T21:54:41Z
[ "python" ]
Python: Do Python Lists keep a count for len() or does it count for each call?
699,177
<p>If I keep calling len() on a very long list, am I wasting time, or does it keep an int count in the background?</p>
35
2009-03-30T21:50:45Z
699,211
<p>A Python "list" is really a resizeable array, not a linked list, so it stores the size somewhere.</p>
3
2009-03-30T22:03:11Z
[ "python" ]
Python: Do Python Lists keep a count for len() or does it count for each call?
699,177
<p>If I keep calling len() on a very long list, am I wasting time, or does it keep an int count in the background?</p>
35
2009-03-30T21:50:45Z
699,236
<p>The question has been answered (<code>len</code> is O(1)), but here's how you can check for yourself:</p> <pre><code>$ python -m timeit -s "l = range(10)" "len(l)" 10000000 loops, best of 3: 0.119 usec per loop $ python -m timeit -s "l = range(1000000)" "len(l)" 10000000 loops, best of 3: 0.131 usec per loop </code...
5
2009-03-30T22:09:01Z
[ "python" ]
Python: Do Python Lists keep a count for len() or does it count for each call?
699,177
<p>If I keep calling len() on a very long list, am I wasting time, or does it keep an int count in the background?</p>
35
2009-03-30T21:50:45Z
699,260
<p>And one more way to find out how it's done is <del><a href="http://www.google.com/codesearch/p?hl=en#ggVSD6_h0Ho/Python-2.5/Objects/listobject.c&amp;q=package:python-2.5%20listobject.c%20lang:c&amp;l=370" rel="nofollow">to look it up on Google Code Search</a></del> <a href="https://github.com/python/cpython/blob/2.5...
19
2009-03-30T22:17:54Z
[ "python" ]
Python: Do Python Lists keep a count for len() or does it count for each call?
699,177
<p>If I keep calling len() on a very long list, am I wasting time, or does it keep an int count in the background?</p>
35
2009-03-30T21:50:45Z
699,275
<p><a href="http://books.google.com/books?id=JnR9hQA3SncC&amp;pg=PA478&amp;dq=Python%2Blen%2Bbig%2BO&amp;ei=JUbRSYPqGofqkwTy9%5FihAQ"><code>len</code> is an O(1) operation</a>.</p>
11
2009-03-30T22:23:13Z
[ "python" ]
Programmatically submitting a form in Python?
699,238
<p>Just started playing with Google App Engine &amp; Python (as an excuse ;)). How do I correctly submit a form like this</p> <pre><code>&lt;form action="https://www.moneybookers.com/app/payment.pl" method="post" target="_blank"&gt; &lt;input type="hidden" name="pay_to_email" value="ENTER_YOUR_USER_EMAIL@MERCHANT.COM"...
2
2009-03-30T22:09:44Z
699,249
<p>By hiding the sensitive bits of the form and submitting it via JavaScript.</p> <p>Make sure you have a good way of referring to the form element...</p> <pre><code>&lt;form ... id="moneybookersForm"&gt;...&lt;/form&gt; </code></pre> <p>... and on page load, execute something like</p> <pre><code>document.getElemen...
0
2009-03-30T22:14:19Z
[ "python", "google-app-engine", "forms", "post" ]
Programmatically submitting a form in Python?
699,238
<p>Just started playing with Google App Engine &amp; Python (as an excuse ;)). How do I correctly submit a form like this</p> <pre><code>&lt;form action="https://www.moneybookers.com/app/payment.pl" method="post" target="_blank"&gt; &lt;input type="hidden" name="pay_to_email" value="ENTER_YOUR_USER_EMAIL@MERCHANT.COM"...
2
2009-03-30T22:09:44Z
699,251
<p>It sounds like you're looking for <a href="http://docs.python.org/library/urllib.html">urllib</a>.</p> <p>Here's an example of POSTing from the library's docs:</p> <pre><code>&gt;&gt;&gt; import urllib &gt;&gt;&gt; params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) &gt;&gt;&gt; f = urllib.urlopen("http:...
6
2009-03-30T22:14:42Z
[ "python", "google-app-engine", "forms", "post" ]
Convert number to binary string
699,285
<p>Is this the best way to convert a Python number to a hex string? </p> <pre><code>number = 123456789 hex(number)[2:-1].decode('hex') </code></pre> <p>Sometimes it doesn't work and complains about Odd-length string when you do 1234567890.</p> <p>Clarification:</p> <p>I am going from int to hex.</p> <p>Also, I nee...
3
2009-03-30T22:26:23Z
699,292
<p>You can use <a href="http://docs.python.org/library/stdtypes.html#string-formatting" rel="nofollow">string formatting</a>:</p> <pre><code>&gt;&gt;&gt; number = 123456789 &gt;&gt;&gt; hex = "%X" % number &gt;&gt;&gt; hex '75BCD15' </code></pre>
6
2009-03-30T22:28:52Z
[ "python", "binary", "hex" ]
Convert number to binary string
699,285
<p>Is this the best way to convert a Python number to a hex string? </p> <pre><code>number = 123456789 hex(number)[2:-1].decode('hex') </code></pre> <p>Sometimes it doesn't work and complains about Odd-length string when you do 1234567890.</p> <p>Clarification:</p> <p>I am going from int to hex.</p> <p>Also, I nee...
3
2009-03-30T22:26:23Z
699,297
<blockquote> <p>Sometimes it doesn't work and complains about Odd-length string when you do 1234567890.</p> </blockquote> <p>Because it doesn't make sense. How do you fit 'AAB' in a space that takes either 2 or 4 digits? Each byte is two hex characters. When you have an odd number of hex characters, the desired resu...
1
2009-03-30T22:31:03Z
[ "python", "binary", "hex" ]
Convert number to binary string
699,285
<p>Is this the best way to convert a Python number to a hex string? </p> <pre><code>number = 123456789 hex(number)[2:-1].decode('hex') </code></pre> <p>Sometimes it doesn't work and complains about Odd-length string when you do 1234567890.</p> <p>Clarification:</p> <p>I am going from int to hex.</p> <p>Also, I nee...
3
2009-03-30T22:26:23Z
699,303
<p>As Paolo mentioned, string formatting is the way to go. Note that you can choose between lower and upper case letters:</p> <pre><code>&gt;&gt;&gt; hex = lambda n: '%X' % n &gt;&gt;&gt; hex(42) '2A' &gt;&gt;&gt; hex = lambda n: '%x' % n &gt;&gt;&gt; hex(42) '2a' &gt;&gt;&gt; def escaped(n): ... s = hex(n) ... ...
0
2009-03-30T22:33:40Z
[ "python", "binary", "hex" ]
Convert number to binary string
699,285
<p>Is this the best way to convert a Python number to a hex string? </p> <pre><code>number = 123456789 hex(number)[2:-1].decode('hex') </code></pre> <p>Sometimes it doesn't work and complains about Odd-length string when you do 1234567890.</p> <p>Clarification:</p> <p>I am going from int to hex.</p> <p>Also, I nee...
3
2009-03-30T22:26:23Z
699,358
<p>If you know how long your output strings should be, string formatting will work. For example, to get four-character strings, you need a formatted length of eight:</p> <pre><code>&gt;&gt;&gt; "{0:08x}".format(123456789).decode("hex") '\x07[\xcd\x15' &gt;&gt;&gt; "{0:08x}".format(1234567890).decode("hex") 'I\x96\x02...
0
2009-03-30T22:47:32Z
[ "python", "binary", "hex" ]
Convert number to binary string
699,285
<p>Is this the best way to convert a Python number to a hex string? </p> <pre><code>number = 123456789 hex(number)[2:-1].decode('hex') </code></pre> <p>Sometimes it doesn't work and complains about Odd-length string when you do 1234567890.</p> <p>Clarification:</p> <p>I am going from int to hex.</p> <p>Also, I nee...
3
2009-03-30T22:26:23Z
699,359
<p>I'm not sure exactly what you want, but have you looked at the <a href="http://docs.python.org/library/struct.html" rel="nofollow"><code>struct</code></a> module?</p> <p>Given</p> <pre><code>&gt;&gt;&gt; hex(123456789) '0x75bcd15' </code></pre> <p>You can do:</p> <pre><code>&gt;&gt;&gt; struct.pack('i', 12345678...
5
2009-03-30T22:47:49Z
[ "python", "binary", "hex" ]
Convert number to binary string
699,285
<p>Is this the best way to convert a Python number to a hex string? </p> <pre><code>number = 123456789 hex(number)[2:-1].decode('hex') </code></pre> <p>Sometimes it doesn't work and complains about Odd-length string when you do 1234567890.</p> <p>Clarification:</p> <p>I am going from int to hex.</p> <p>Also, I nee...
3
2009-03-30T22:26:23Z
3,139,769
<p>one of the surest way, for arbitary numbers, is to use the 'array' module like this:</p> <pre><code>from array import array binArr = array('B') while(data): d = data &amp; 0xFF binArr.append(d) data &gt;&gt;= 8 hexStr = binArr.tostring() </code></pre>
0
2010-06-29T10:23:44Z
[ "python", "binary", "hex" ]