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 |
|---|---|---|---|---|---|---|---|---|---|
python single configuration file | 2,348,927 | <p>I am developing a project that requires a single configuration file whose data is used by multiple modules.<br>
My question is: what is the common approach to that? should i read the configuration file from each
of my modules (files) or is there any other way to do it?</p>
<p>I was thinking to have a module named c... | 20 | 2010-02-27T20:53:15Z | 2,348,941 | <p>The approach you describe is ok. If you want to add support for user config files, you can use <code>execfile(os.path.expanduser("~/.yourprogram/config.py"))</code>.</p>
| 4 | 2010-02-27T20:57:20Z | [
"python",
"configuration-files"
] |
python single configuration file | 2,348,927 | <p>I am developing a project that requires a single configuration file whose data is used by multiple modules.<br>
My question is: what is the common approach to that? should i read the configuration file from each
of my modules (files) or is there any other way to do it?</p>
<p>I was thinking to have a module named c... | 20 | 2010-02-27T20:53:15Z | 2,349,159 | <p>One nice approach is to parse the config file(s) into a Python object when the application starts and pass this object around to all classes and modules requiring access to the configuration. </p>
<p>This may save a lot of time parsing the config.</p>
| 3 | 2010-02-27T22:23:40Z | [
"python",
"configuration-files"
] |
python single configuration file | 2,348,927 | <p>I am developing a project that requires a single configuration file whose data is used by multiple modules.<br>
My question is: what is the common approach to that? should i read the configuration file from each
of my modules (files) or is there any other way to do it?</p>
<p>I was thinking to have a module named c... | 20 | 2010-02-27T20:53:15Z | 2,349,182 | <p>I like the approach of a single <code>config.py</code> module whose body (when first imported) parses one or more configuration-data files and sets its own "global variables" appropriately -- though I'd favor <code>config.teamdata</code> over the round-about <code>config.data['teamdata']</code> approach.</p>
<p>Thi... | 9 | 2010-02-27T22:30:47Z | [
"python",
"configuration-files"
] |
python single configuration file | 2,348,927 | <p>I am developing a project that requires a single configuration file whose data is used by multiple modules.<br>
My question is: what is the common approach to that? should i read the configuration file from each
of my modules (files) or is there any other way to do it?</p>
<p>I was thinking to have a module named c... | 20 | 2010-02-27T20:53:15Z | 2,349,579 | <p>If you want to share your config across different machines, you could perhaps put it on a web server and do import like this:</p>
<pre><code>import urllib2
confstr = urllib2.urlopen("http://yourhost/config.py").read()
exec(confstr)
</code></pre>
<p>And if you want to share it across different languages, perhaps yo... | 1 | 2010-02-28T00:44:40Z | [
"python",
"configuration-files"
] |
Unable to get custom context processor to be invoked | 2,348,943 | <p>I am trying to create a custom context processor which will render a list of menu items for a logged in user. I have done the following:</p>
<hr>
<p>Within my settings.py I have</p>
<pre>
TEMPLATE_CONTEXT_PROCESSOR = (
'django.contrib.auth.context_processors.auth',
'mysite.accounts.context_processors.user... | 8 | 2010-02-27T20:57:46Z | 2,348,959 | <p>The setting name should be <code>TEMPLATE_CONTEXT_PROCESSORS</code>, with an S.</p>
| 5 | 2010-02-27T21:00:36Z | [
"python",
"django",
"django-templates",
"django-context"
] |
How can I use Boost::Python to add a method to an exported class without modifying the base class? | 2,348,960 | <p>I have a class in C++ that I can't modify. However, that class holds an std::list<> of items that I need to be able to access in a Python extension. Since Boost::Python doesn't seem to have a built-in conversion between an std::list and a Python list, I was hoping to be able to write a method in C++ that could ... | 1 | 2010-02-27T21:00:37Z | 2,376,513 | <p>Boost provides a helper to wrap iterators which is documented here: <a href="http://www.boost.org/doc/libs/1_42_0/libs/python/doc/v2/iterator.html" rel="nofollow">http://www.boost.org/doc/libs/1_42_0/libs/python/doc/v2/iterator.html</a></p>
<p>The example hear the end of that page worked for me, you just need to ex... | 1 | 2010-03-04T02:28:56Z | [
"c++",
"python",
"boost-python"
] |
How can I use Boost::Python to add a method to an exported class without modifying the base class? | 2,348,960 | <p>I have a class in C++ that I can't modify. However, that class holds an std::list<> of items that I need to be able to access in a Python extension. Since Boost::Python doesn't seem to have a built-in conversion between an std::list and a Python list, I was hoping to be able to write a method in C++ that could ... | 1 | 2010-02-27T21:00:37Z | 4,147,107 | <p>To answer the question in a more general way, you can attach any c++ function that has the right signature to the python export in the class_ declaration. </p>
<p>assume a class foo:</p>
<pre><code>struct foo
{
//class stuff here
}
</code></pre>
<p>You can define a free function that takes a reference to foo ... | 3 | 2010-11-10T17:17:27Z | [
"c++",
"python",
"boost-python"
] |
Accessing Lower Triangle of a Numpy Matrix? | 2,349,260 | <p>Okay, so basically lets say i have a matrix:</p>
<pre><code>matrix([[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4]])
</code></pre>
<p>Is it possible to get the area below the diagonal easily when working with numpy matrixs? I looked around and co... | 4 | 2010-02-27T22:51:55Z | 2,349,327 | <p>You could use <code>tril</code> and <code>triu</code>. See them here:
<a href="http://docs.scipy.org/doc/numpy/reference/routines.array-creation.html">http://docs.scipy.org/doc/numpy/reference/routines.array-creation.html</a></p>
| 11 | 2010-02-27T23:09:08Z | [
"python",
"numpy"
] |
Accessing Lower Triangle of a Numpy Matrix? | 2,349,260 | <p>Okay, so basically lets say i have a matrix:</p>
<pre><code>matrix([[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4]])
</code></pre>
<p>Is it possible to get the area below the diagonal easily when working with numpy matrixs? I looked around and co... | 4 | 2010-02-27T22:51:55Z | 6,039,924 | <pre><code>def tri_flat(array):
R = array.shape[0]
mask = np.asarray(np.invert(np.tri(R,R,dtype=bool)),dtype=float)
x,y = mask.nonzero()
return array[x,y]
</code></pre>
<p>I was looking for a convenience function myself, but this'll have to do... not sure it gets much easier. But if it does, I'd be int... | 2 | 2011-05-18T04:37:09Z | [
"python",
"numpy"
] |
What can I do if django runserver seems to be caching my urls.py and settings.py? | 2,349,302 | <p>I detected this problem when updating the patterns in URLConf and seeing that the new pattern wasn't matched anywhere.</p>
<p>So, with urls.py I don't get anywhere when writing random lines on it, I mean, invalid code, and django doesn't throw any exception and serves the urls just fine.</p>
<p>So I checked <code>... | 1 | 2010-02-27T23:02:35Z | 2,349,845 | <p>You're not running what you think you're running. Check your <code>PYTHONPATH</code>.</p>
| 2 | 2010-02-28T02:41:25Z | [
"python",
"django",
"url"
] |
Why am I getting an AttributeError when I have the attribute? | 2,349,365 | <p>I keep getting the following error:</p>
<pre><code>AttributeError: Caribou instance has no attribute 'on_key_up'
</code></pre>
<p>The problem is, I'm pretty sure I do have that attribute...</p>
<p>Here are some excerpts from my code (from caribou.py):</p>
<pre><code> def on_key_up(self, event):
if event.event_... | 1 | 2010-02-27T23:26:06Z | 2,349,382 | <p>You aren't showing your import statements or how "caribou" the <strong>instance</strong> is being created. My guess is you are trying to pass caribou.on_key_up as in caribou the <strong>module</strong>, not the <strong>instance</strong>.</p>
| 1 | 2010-02-27T23:31:48Z | [
"python",
"attributeerror"
] |
Why am I getting an AttributeError when I have the attribute? | 2,349,365 | <p>I keep getting the following error:</p>
<pre><code>AttributeError: Caribou instance has no attribute 'on_key_up'
</code></pre>
<p>The problem is, I'm pretty sure I do have that attribute...</p>
<p>Here are some excerpts from my code (from caribou.py):</p>
<pre><code> def on_key_up(self, event):
if event.event_... | 1 | 2010-02-27T23:26:06Z | 2,349,559 | <p>What happens if you print dir(caribou)? Do you see your method?</p>
| 2 | 2010-02-28T00:38:51Z | [
"python",
"attributeerror"
] |
Why am I getting an AttributeError when I have the attribute? | 2,349,365 | <p>I keep getting the following error:</p>
<pre><code>AttributeError: Caribou instance has no attribute 'on_key_up'
</code></pre>
<p>The problem is, I'm pretty sure I do have that attribute...</p>
<p>Here are some excerpts from my code (from caribou.py):</p>
<pre><code> def on_key_up(self, event):
if event.event_... | 1 | 2010-02-27T23:26:06Z | 2,350,057 | <p>The OP mentions in a comment that <code>dir(caribou)</code> gives him:</p>
<pre><code>['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
</code></pre>
<p>so it <strong>definitely</strong> looks at that point that <code>caribou</code> is a <strong>module</strong> -- nothing else would no... | 4 | 2010-02-28T04:13:02Z | [
"python",
"attributeerror"
] |
Looping Redirect with PyFacebook and Google App Engine | 2,349,368 | <p>I have a Python Facebook project hosted on Google App Engine and use the following code to handle initialization of the Facebook API using PyFacebook.</p>
<pre><code># Facebook Initialization
def initialize_facebook(f):
# Redirection handler
def redirect(self, url):
logger.info('Redirecting the use... | 1 | 2010-02-27T23:28:16Z | 2,394,319 | <p>The problem seems familiar.
May you can use the solution from my question here:</p>
<p><a href="http://stackoverflow.com/questions/2039366/app-engine-patch-and-pyfacebook-not-working">http://stackoverflow.com/questions/2039366/app-engine-patch-and-pyfacebook-not-working</a></p>
<p>But that was with the decorator t... | 0 | 2010-03-06T22:26:03Z | [
"python",
"google-app-engine",
"redirect",
"pyfacebook"
] |
Looping Redirect with PyFacebook and Google App Engine | 2,349,368 | <p>I have a Python Facebook project hosted on Google App Engine and use the following code to handle initialization of the Facebook API using PyFacebook.</p>
<pre><code># Facebook Initialization
def initialize_facebook(f):
# Redirection handler
def redirect(self, url):
logger.info('Redirecting the use... | 1 | 2010-02-27T23:28:16Z | 2,467,550 | <p>I was just having the exact same thing happen to me today! What I think is happening is that fbapi.check_session() is not setting fbapi.added correctly. I don't think the <a href="http://wiki.developers.facebook.com/index.php/Post-Add_URL" rel="nofollow">Post-Add URL</a> contains 'installed' anymore, but still has... | 2 | 2010-03-18T04:35:56Z | [
"python",
"google-app-engine",
"redirect",
"pyfacebook"
] |
How many private variables are too many? Capsulizing classes? Class Practices? | 2,349,529 | <p>Okay so i am currently working on an inhouse statistics package for python, its mainly geared towards a combination of working with arcgis geoprocessor, for modeling comparasion and tools.</p>
<p>Anyways, so i have a single class, that calculates statistics. Lets just call it Stats. Now my Stats class, is getting t... | 3 | 2010-02-28T00:27:38Z | 2,349,635 | <p>I can think of a couple of solutions. One would be to simply store values in an array with an enum like so:</p>
<pre><code>StatisticType = enum('AveragePerDay','MedianPerDay'...)
</code></pre>
<p>Another would be to use a inheritance like so:</p>
<pre><code>class StatisticBase
....
class AveragePerDay ( Statistic... | 1 | 2010-02-28T01:03:03Z | [
"python",
"class"
] |
How many private variables are too many? Capsulizing classes? Class Practices? | 2,349,529 | <p>Okay so i am currently working on an inhouse statistics package for python, its mainly geared towards a combination of working with arcgis geoprocessor, for modeling comparasion and tools.</p>
<p>Anyways, so i have a single class, that calculates statistics. Lets just call it Stats. Now my Stats class, is getting t... | 3 | 2010-02-28T00:27:38Z | 2,349,637 | <p>Why not create a class for each statistic you need to compute and when of the statistics requires other, just pass an instance of the latter to the computing method? However, there is little known about your code and required functionalities. Maybe you could describe in a broader fashion, what kind of statistics you... | 1 | 2010-02-28T01:04:02Z | [
"python",
"class"
] |
How many private variables are too many? Capsulizing classes? Class Practices? | 2,349,529 | <p>Okay so i am currently working on an inhouse statistics package for python, its mainly geared towards a combination of working with arcgis geoprocessor, for modeling comparasion and tools.</p>
<p>Anyways, so i have a single class, that calculates statistics. Lets just call it Stats. Now my Stats class, is getting t... | 3 | 2010-02-28T00:27:38Z | 2,349,981 | <p>It's a common anti-pattern for a class to become "too fat" (have too much functionality and related state), and while this is commonly observed about "base classes" (whence the "fat base class" monicker for the anti-pattern), it can really happen without any inheritance involved.</p>
<p>Many design patterns (DPs fo... | 0 | 2010-02-28T03:35:56Z | [
"python",
"class"
] |
How many private variables are too many? Capsulizing classes? Class Practices? | 2,349,529 | <p>Okay so i am currently working on an inhouse statistics package for python, its mainly geared towards a combination of working with arcgis geoprocessor, for modeling comparasion and tools.</p>
<p>Anyways, so i have a single class, that calculates statistics. Lets just call it Stats. Now my Stats class, is getting t... | 3 | 2010-02-28T00:27:38Z | 2,350,005 | <p>Since you are asking about best practices you might want to check out pylint (http://www.logilab.org/857). It has many good suggestions about code style including ones relating to how many private variables in a class.</p>
| 0 | 2010-02-28T03:44:54Z | [
"python",
"class"
] |
Attempting to insert an integer from a list into datetime object | 2,349,551 | <p>What I am trying to accomplish is very simple: creating a loop from a range (pretty self explanatory below) that will insert the month into the datetime object. I know %d requires an integer, and I know that 'month' type is int...so I'm kind of stuck as to why I can't substitute my month variable. Here is my code:... | 2 | 2010-02-28T00:36:50Z | 2,349,577 | <p><code>month</code> is a variable and you can use it to create the datetime object. I think you want to do the following:</p>
<pre><code>month_start = datetime.date(2010, month, 1)
next_month_begin = datetime.date(2010, month+1, 1)
</code></pre>
<p>That will work, because datetime.date() requires 3 integer argument... | 0 | 2010-02-28T00:44:23Z | [
"python",
"datetime",
"range"
] |
Attempting to insert an integer from a list into datetime object | 2,349,551 | <p>What I am trying to accomplish is very simple: creating a loop from a range (pretty self explanatory below) that will insert the month into the datetime object. I know %d requires an integer, and I know that 'month' type is int...so I'm kind of stuck as to why I can't substitute my month variable. Here is my code:... | 2 | 2010-02-28T00:36:50Z | 2,349,613 | <p>There are a few things that you need to fix here.</p>
<p>EDIT: First, be careful with your range, since you are using month+1 to create next_month_begin, you do not want this to be greater than 12 or you will get an error.</p>
<p>Next, when you are trying to create the date object you are passing the month in as a... | 2 | 2010-02-28T00:55:22Z | [
"python",
"datetime",
"range"
] |
Attempting to insert an integer from a list into datetime object | 2,349,551 | <p>What I am trying to accomplish is very simple: creating a loop from a range (pretty self explanatory below) that will insert the month into the datetime object. I know %d requires an integer, and I know that 'month' type is int...so I'm kind of stuck as to why I can't substitute my month variable. Here is my code:... | 2 | 2010-02-28T00:36:50Z | 2,350,013 | <p>You've got other answers, but here's a way to get the last day of the month. Adding 31 days will get you into the next month regardless of the number of days in the current month, then moving back to the first and subtracting a day will give the ending date.</p>
<pre><code>import datetime
for month in range(1,13):... | 2 | 2010-02-28T03:48:19Z | [
"python",
"datetime",
"range"
] |
Attempting to insert an integer from a list into datetime object | 2,349,551 | <p>What I am trying to accomplish is very simple: creating a loop from a range (pretty self explanatory below) that will insert the month into the datetime object. I know %d requires an integer, and I know that 'month' type is int...so I'm kind of stuck as to why I can't substitute my month variable. Here is my code:... | 2 | 2010-02-28T00:36:50Z | 2,352,294 | <p>Check out the calendar module (http://docs.python.org/library/calendar.html).</p>
<p>It has batteries included for this sort of thing...</p>
<p>You could just do:</p>
<pre><code>from calendar import Calendar
def start_and_end_days(year, month):
cal = Calendar()
month_days = [day for day in cal.itermonthda... | 0 | 2010-02-28T19:20:32Z | [
"python",
"datetime",
"range"
] |
Unable to access database from within a method | 2,349,614 | <p>I keep receiving the error, "<strong>TypeError: 'Shard' object is unsubscriptable</strong>."</p>
<pre><code>#Establish an on-demand connection to the central database
def connectCentral():
engine = engine_from_config(config, 'sqlalchemy.central.')
central.engine = engine
central.Session.configure(bind=e... | 1 | 2010-02-28T00:55:23Z | 2,349,928 | <p>Given the incomplete snippet of code you've given, the only relevant line is: </p>
<pre><code>shard.Session.configure(bind=shard.engine)
</code></pre>
<p>The error indication is a base Python type error, a scalar (or None) needed to be subscripted inside SQLAlchemy. This almost certainly is the result of an incomp... | 0 | 2010-02-28T03:16:34Z | [
"python",
"sqlalchemy",
"pylons"
] |
Unable to access database from within a method | 2,349,614 | <p>I keep receiving the error, "<strong>TypeError: 'Shard' object is unsubscriptable</strong>."</p>
<pre><code>#Establish an on-demand connection to the central database
def connectCentral():
engine = engine_from_config(config, 'sqlalchemy.central.')
central.engine = engine
central.Session.configure(bind=e... | 1 | 2010-02-28T00:55:23Z | 3,199,395 | <p>My guess is that the error is in this line:</p>
<pre>
shard.engine = shard_info['sqlite']
</pre>
<p>because shard_info is the only object of Shard class that I can see, and it's the only subscription operation in the code pasted. The traceback shows a different line, so perhaps you edited the source after it ... | 0 | 2010-07-07T22:29:13Z | [
"python",
"sqlalchemy",
"pylons"
] |
Process for converting python program into threaded application? | 2,349,876 | <p>I have a code-base that I'm looking to split up and add to by using threading, however I'm relatively new on how to handle it. Please before reading further respect my wish of NOT just re-writing this code and tossing it back at me with the problem solved. I would much rather work the problem out by someone pointi... | 1 | 2010-02-28T02:58:52Z | 2,349,945 | <p>As long as you have a single thread (as in the above snippet, where you instantiate <code>Recon</code> just once), it shouldn't matter much what you do where; but of course I imagine the reason you're introducing threading is to eventually move to having multiple threads active.</p>
<p>If that's the case, then the ... | 3 | 2010-02-28T03:23:00Z | [
"python",
"multithreading"
] |
Python: How to import other Python files | 2,349,991 | <p>How do I import other files in Python?</p>
<ol>
<li>How exactly can I import a specific python file like <code>import file.py</code>?</li>
<li>How to import a folder instead of a specific file?</li>
<li>I want to load a Python file dynamically in runtime, based on user
input.</li>
<li>I want to know how to take fro... | 218 | 2010-02-28T03:40:11Z | 2,349,998 | <ol>
<li><p>Just <code>import file</code> without the '.py' extension</p></li>
<li><p>You can mark a folder as a package, by adding an empty file named <code>__init__.py</code>.</p></li>
<li><p>You can use <code>__import__</code> function, it takes the name as the module name as string. (again: module name without .py ... | 153 | 2010-02-28T03:42:33Z | [
"python",
"python-import"
] |
Python: How to import other Python files | 2,349,991 | <p>How do I import other files in Python?</p>
<ol>
<li>How exactly can I import a specific python file like <code>import file.py</code>?</li>
<li>How to import a folder instead of a specific file?</li>
<li>I want to load a Python file dynamically in runtime, based on user
input.</li>
<li>I want to know how to take fro... | 218 | 2010-02-28T03:40:11Z | 14,503,276 | <p>You do not have many complex methods to import a python file from one folder to another. Just create a <strong>__init__.py</strong> file to declare this folder is a python package and then go to your host file where you want to import just type </p>
<p><code>from root.parent.folder.file import variable, class, what... | 14 | 2013-01-24T14:08:54Z | [
"python",
"python-import"
] |
Python: How to import other Python files | 2,349,991 | <p>How do I import other files in Python?</p>
<ol>
<li>How exactly can I import a specific python file like <code>import file.py</code>?</li>
<li>How to import a folder instead of a specific file?</li>
<li>I want to load a Python file dynamically in runtime, based on user
input.</li>
<li>I want to know how to take fro... | 218 | 2010-02-28T03:40:11Z | 16,299,963 | <p>To import a specific Python file at 'runtime' with a known name:</p>
<pre><code>import os
import sys
</code></pre>
<p>...</p>
<pre><code>scriptpath = "../Test/MyModule.py"
# Add the directory containing your module to the Python path (wants absolute paths)
sys.path.append(os.path.abspath(scriptpath))
# Do the i... | 18 | 2013-04-30T12:30:38Z | [
"python",
"python-import"
] |
Python: How to import other Python files | 2,349,991 | <p>How do I import other files in Python?</p>
<ol>
<li>How exactly can I import a specific python file like <code>import file.py</code>?</li>
<li>How to import a folder instead of a specific file?</li>
<li>I want to load a Python file dynamically in runtime, based on user
input.</li>
<li>I want to know how to take fro... | 218 | 2010-02-28T03:40:11Z | 20,749,411 | <h2>There are many ways to import a python file, all with their pros and cons.</h2>
<p>Don't just hastily pick the first import strategy that works for you or else you'll have to rewrite the codebase later on when you find it doesn't meet your needs. </p>
<p>I'll start out explaining the easiest example #1, then I'l... | 353 | 2013-12-23T18:46:10Z | [
"python",
"python-import"
] |
Python: How to import other Python files | 2,349,991 | <p>How do I import other files in Python?</p>
<ol>
<li>How exactly can I import a specific python file like <code>import file.py</code>?</li>
<li>How to import a folder instead of a specific file?</li>
<li>I want to load a Python file dynamically in runtime, based on user
input.</li>
<li>I want to know how to take fro... | 218 | 2010-02-28T03:40:11Z | 32,903,271 | <p><a href="http://www.tutorialspoint.com/python/python_modules.htm" rel="nofollow">Import doc ..</a>The <strong>init</strong>.py files are required to make Python treat the directories as containing packages, this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modu... | 4 | 2015-10-02T08:27:54Z | [
"python",
"python-import"
] |
Python: How to import other Python files | 2,349,991 | <p>How do I import other files in Python?</p>
<ol>
<li>How exactly can I import a specific python file like <code>import file.py</code>?</li>
<li>How to import a folder instead of a specific file?</li>
<li>I want to load a Python file dynamically in runtime, based on user
input.</li>
<li>I want to know how to take fro... | 218 | 2010-02-28T03:40:11Z | 37,111,623 | <p>How I import is import the file and use shorthand of it's name.</p>
<pre><code>import DoStuff.py as DS
DS.main()
</code></pre>
<p><strong>Don't forget</strong> that your importing file <strong>MUST BE</strong> named with .py extension</p>
| 2 | 2016-05-09T09:01:49Z | [
"python",
"python-import"
] |
python csv header error | 2,350,018 | <p>Trying to read headers for a csv file with:</p>
<pre><code>reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True)
headers = reader.fieldnames
for header in sorted(set(headers)):
</code></pre>
<p>It worked on development server, throws this error on production</p>
<pre><code>'NoneType' object is not itera... | 0 | 2010-02-28T03:49:28Z | 2,350,067 | <p>Maybe you're using different Python versions in your development server vs production? In Python 2.5, the <code>fieldnames</code> attribute of a <code>DictReader</code> instance is <code>None</code> until the instance has been used to fetch at least one row.</p>
| 1 | 2010-02-28T04:19:17Z | [
"python",
"csv"
] |
python csv header error | 2,350,018 | <p>Trying to read headers for a csv file with:</p>
<pre><code>reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True)
headers = reader.fieldnames
for header in sorted(set(headers)):
</code></pre>
<p>It worked on development server, throws this error on production</p>
<pre><code>'NoneType' object is not itera... | 0 | 2010-02-28T03:49:28Z | 2,350,073 | <p>From <a href="http://docs.python.org/library/csv.html#csv.csvreader.fieldnames" rel="nofollow"><code>csvreader.fieldnames</code> documentation</a>:</p>
<blockquote>
<p>If not passed as a parameter when creating the object, this attribute is initialized <strong>upon first access or when the first record is read fr... | 2 | 2010-02-28T04:22:06Z | [
"python",
"csv"
] |
How to build a web crawler based on Scrapy to run forever? | 2,350,049 | <p>I want to build a web crawler based on Scrapy to grab news pictures from several news portal website. I want to this crawler to be:</p>
<ol>
<li><p>Run forever</p>
<p>Means it will periodical re-visit some portal pages to get updates.</p></li>
<li><p>Schedule priorities. </p>
<p>Give different priorities to diffe... | 11 | 2010-02-28T04:07:13Z | 2,350,109 | <p>Scrapy is a framework for the spidering of websites, as such, it is intended to support your criteria but it isn't going to dance for you out of the box; you will probably have to get relatively familiar with the module for some tasks. </p>
<ol>
<li>Running forever is up to your application that calls Scrapy. You t... | 12 | 2010-02-28T04:47:32Z | [
"python",
"web-crawler",
"scrapy"
] |
How to build a web crawler based on Scrapy to run forever? | 2,350,049 | <p>I want to build a web crawler based on Scrapy to grab news pictures from several news portal website. I want to this crawler to be:</p>
<ol>
<li><p>Run forever</p>
<p>Means it will periodical re-visit some portal pages to get updates.</p></li>
<li><p>Schedule priorities. </p>
<p>Give different priorities to diffe... | 11 | 2010-02-28T04:07:13Z | 39,009,546 | <p>About the requirement on running-forever, here's some details.</p>
<p>You need to catch the <code>signals.spider_idle</code> signal, and in your method that
connected to the signal, you need to raise a <code>DontCloseSpider</code> exception. The <code>spider_idle</code> signal is sent to the scrapy engine when the... | 0 | 2016-08-18T03:30:27Z | [
"python",
"web-crawler",
"scrapy"
] |
Python: does the set class "leak" when items are removed, like a dict? | 2,350,050 | <p>I know that Python <code>dict</code>s will "leak" when items are removed (because the item's slot will be overwritten with the magic "removed" value)⦠But will the <code>set</code> class behave the same way? Is it safe to keep a <code>set</code> around, adding and removing stuff from it over time?</p>
<p><strong>... | 4 | 2010-02-28T04:08:43Z | 2,350,061 | <p>Yes, <code>set</code> is basically a hash table just like <code>dict</code> -- the differences at the interface don't imply many differences "below" it. Once in a while, you should copy the set -- <code>myset = set(myset)</code> -- just like you should for a dict on which many additions and removals are regularly m... | 7 | 2010-02-28T04:14:41Z | [
"python",
"set",
"dictionary"
] |
Python: does the set class "leak" when items are removed, like a dict? | 2,350,050 | <p>I know that Python <code>dict</code>s will "leak" when items are removed (because the item's slot will be overwritten with the magic "removed" value)⦠But will the <code>set</code> class behave the same way? Is it safe to keep a <code>set</code> around, adding and removing stuff from it over time?</p>
<p><strong>... | 4 | 2010-02-28T04:08:43Z | 2,350,076 | <p>For questions like these it is often best to run a quick experiment like this one and see what happens:</p>
<pre><code>s = set()
for a in range(1000):
for b in range(10000000):
s.add(b)
for b in range(10000000):
s.remove(b)
</code></pre>
<p>What docs and people say and what behaviour actually is are of... | -1 | 2010-02-28T04:24:19Z | [
"python",
"set",
"dictionary"
] |
Custom data types in numpy arrays | 2,350,072 | <p>I'm creating a numpy array which is to be filled with objects of a particular class I've made. I'd like to initialize the array such that it will only ever contain objects of that class. For example, here's what I'd like to do, and what happens if I do it. </p>
<pre><code>class Kernel:
pass
>>> L = np... | 17 | 2010-02-28T04:21:15Z | 2,350,105 | <p>It has to be a Numpy scalar type:</p>
<p><a href="http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html#arrays-scalars-built-in" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html#arrays-scalars-built-in</a></p>
<p>or a subclass of ndarray:</p>
<p><a href="http://docs.scipy.org/d... | 3 | 2010-02-28T04:44:36Z | [
"python",
"numpy"
] |
Custom data types in numpy arrays | 2,350,072 | <p>I'm creating a numpy array which is to be filled with objects of a particular class I've made. I'd like to initialize the array such that it will only ever contain objects of that class. For example, here's what I'd like to do, and what happens if I do it. </p>
<pre><code>class Kernel:
pass
>>> L = np... | 17 | 2010-02-28T04:21:15Z | 2,350,826 | <p>As far as I know, enforcing a single type for elements in a numpy.ndarray has to be done manually (unless the array contains Numpy scalars): there is no built-in checking mechanism (your array has dtype=object). If you really want to enforce a single type, you have to subclass ndarray and implement the checks in th... | 1 | 2010-02-28T10:58:26Z | [
"python",
"numpy"
] |
Custom data types in numpy arrays | 2,350,072 | <p>I'm creating a numpy array which is to be filled with objects of a particular class I've made. I'd like to initialize the array such that it will only ever contain objects of that class. For example, here's what I'd like to do, and what happens if I do it. </p>
<pre><code>class Kernel:
pass
>>> L = np... | 17 | 2010-02-28T04:21:15Z | 2,352,846 | <p>If your Kernel class has a predictable amount of member data, then you could define a dtype for it instead of a class. e.g. if it's parameterized by 9 floats and an int, you could do</p>
<pre><code>kerneldt = np.dtype([('myintname', np.int32), ('myfloats', np.float64, 9)])
arr = np.empty(dims, dtype=kerneldt)
</cod... | 15 | 2010-02-28T21:57:18Z | [
"python",
"numpy"
] |
Building an interleaved buffer for pyopengl and numpy | 2,350,110 | <p>I'm trying to batch up a bunch of vertices and texture coords in an interleaved array before sending it to pyOpengl's glInterleavedArrays/glDrawArrays. The only problem is that I'm unable to find a suitably fast enough way to append data into a numpy array. </p>
<p>Is there a better way to do this? I would have ... | 7 | 2010-02-28T04:48:19Z | 2,352,629 | <p>The reason that create_array_1 is so much faster seems to be that the items in the (python) list all point to the same object. You can see this if you test:</p>
<pre><code>print (ibuffer[0] is ibuffer[1])
</code></pre>
<p>inside the subroutines. In create_array_1 this is true (before you create the numpy array), w... | 1 | 2010-02-28T20:55:15Z | [
"python",
"opengl",
"numpy",
"2d",
"pyopengl"
] |
Building an interleaved buffer for pyopengl and numpy | 2,350,110 | <p>I'm trying to batch up a bunch of vertices and texture coords in an interleaved array before sending it to pyOpengl's glInterleavedArrays/glDrawArrays. The only problem is that I'm unable to find a suitably fast enough way to append data into a numpy array. </p>
<p>Is there a better way to do this? I would have ... | 7 | 2010-02-28T04:48:19Z | 2,359,008 | <p>I know it seems strange, but have you tried <code>fromfile</code>?</p>
| 0 | 2010-03-01T20:55:08Z | [
"python",
"opengl",
"numpy",
"2d",
"pyopengl"
] |
Building an interleaved buffer for pyopengl and numpy | 2,350,110 | <p>I'm trying to batch up a bunch of vertices and texture coords in an interleaved array before sending it to pyOpengl's glInterleavedArrays/glDrawArrays. The only problem is that I'm unable to find a suitably fast enough way to append data into a numpy array. </p>
<p>Is there a better way to do this? I would have ... | 7 | 2010-02-28T04:48:19Z | 2,361,191 | <p>The benefit of numpy is not realized by simply storing the data in an array, it is achieved by performing operations across many elements in an array instead of one by one. Your example can be boiled down and optimized to this trivial solution with orders of magnitude speedup:</p>
<pre><code>numpy.random.standard_... | 1 | 2010-03-02T06:00:34Z | [
"python",
"opengl",
"numpy",
"2d",
"pyopengl"
] |
How do I print a line following a line containing certain text in a saved file in Python? | 2,350,190 | <p>I have written a Python program to find the carrier of a cell phone given the number. It downloads the source of <a href="http://www.whitepages.com/carrier_lookup?carrier=other&number_0=1112223333&response=1" rel="nofollow">http://www.whitepages.com/carrier_lookup?carrier=other&number_0=1112223333&re... | 0 | 2010-02-28T05:25:44Z | 2,350,203 | <p>You should be using a HTML parser such as <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow"><code>BeautifulSoup</code></a> or <a href="http://codespeak.net/lxml/" rel="nofollow"><code>lxml</code></a> instead.</p>
| 2 | 2010-02-28T05:31:52Z | [
"python",
"html",
"string",
"parsing"
] |
How do I print a line following a line containing certain text in a saved file in Python? | 2,350,190 | <p>I have written a Python program to find the carrier of a cell phone given the number. It downloads the source of <a href="http://www.whitepages.com/carrier_lookup?carrier=other&number_0=1112223333&response=1" rel="nofollow">http://www.whitepages.com/carrier_lookup?carrier=other&number_0=1112223333&re... | 0 | 2010-02-28T05:25:44Z | 2,350,206 | <p>What you really want to be doing is parsing the HTML properly. Use the BeautifulSoup library - it's wonderful at doing so.</p>
<p>Sample code:</p>
<pre><code>import urllib2, BeautifulSoup
opener = urllib2.build_opener()
opener.addheaders[0] = ('User-agent', 'Mozilla/5.1')
response = opener.open('http://www.white... | 4 | 2010-02-28T05:32:42Z | [
"python",
"html",
"string",
"parsing"
] |
How do I print a line following a line containing certain text in a saved file in Python? | 2,350,190 | <p>I have written a Python program to find the carrier of a cell phone given the number. It downloads the source of <a href="http://www.whitepages.com/carrier_lookup?carrier=other&number_0=1112223333&response=1" rel="nofollow">http://www.whitepages.com/carrier_lookup?carrier=other&number_0=1112223333&re... | 0 | 2010-02-28T05:25:44Z | 2,350,207 | <p>to get the next line, you can use </p>
<pre><code>htmlsource = open('carrier.html', 'r')
for line in htmlsource:
if '<div class="carrier_result">' in line:
nextline = htmlsource.next()
print nextline
</code></pre>
<p>A "better" way is to split on <code></div></code>, then get the ... | 2 | 2010-02-28T05:32:51Z | [
"python",
"html",
"string",
"parsing"
] |
pymongo: findandmodify - "no such command" is returned | 2,350,238 | <p>I believe there is a bug in pymongo (or, at least, the documentation) which makes it impossible to run a <code>findandupdate</code> query.</p>
<p>Here's what happens. When I run:</p>
<pre><code> result = db.command({
'findandmodify': 'my_collection',
'query': {'foo': 'bar'},
'update': {'... | 2 | 2010-02-28T05:54:21Z | 2,350,350 | <p>One workaround may be to construct the JavaScript version of the command and pass it to db.eval().</p>
<pre><code>db.eval('db.runCommand({"findandmodify": "my_collection", "query": {"foo": "bar"}, "update": {"$set": {"status": "queued"}},})')
</code></pre>
<p>The issue is that, as Alex mentioned, Python dicts have... | 2 | 2010-02-28T06:50:15Z | [
"python",
"mongodb",
"pymongo"
] |
pymongo: findandmodify - "no such command" is returned | 2,350,238 | <p>I believe there is a bug in pymongo (or, at least, the documentation) which makes it impossible to run a <code>findandupdate</code> query.</p>
<p>Here's what happens. When I run:</p>
<pre><code> result = db.command({
'findandmodify': 'my_collection',
'query': {'foo': 'bar'},
'update': {'... | 2 | 2010-02-28T05:54:21Z | 2,351,530 | <p>For languages that don't have a built-in sorted dict type the mongo drivers include one. In python that is the SON type: <a href="http://api.mongodb.org/python/1.4%2B/api/pymongo/son.html">http://api.mongodb.org/python/1.4%2B/api/pymongo/son.html</a>. You will need to use that for all commands.</p>
<p>If that still... | 6 | 2010-02-28T15:38:40Z | [
"python",
"mongodb",
"pymongo"
] |
pymongo: findandmodify - "no such command" is returned | 2,350,238 | <p>I believe there is a bug in pymongo (or, at least, the documentation) which makes it impossible to run a <code>findandupdate</code> query.</p>
<p>Here's what happens. When I run:</p>
<pre><code> result = db.command({
'findandmodify': 'my_collection',
'query': {'foo': 'bar'},
'update': {'... | 2 | 2010-02-28T05:54:21Z | 6,241,024 | <p>current pymongo api has find_and_modify built-in
see more at <a href="https://github.com/mongodb/mongo-python-driver/blob/master/pymongo/collection.py#L1035" rel="nofollow">https://github.com/mongodb/mongo-python-driver/blob/master/pymongo/collection.py#L1035</a></p>
| 3 | 2011-06-05T04:35:00Z | [
"python",
"mongodb",
"pymongo"
] |
pymongo: findandmodify - "no such command" is returned | 2,350,238 | <p>I believe there is a bug in pymongo (or, at least, the documentation) which makes it impossible to run a <code>findandupdate</code> query.</p>
<p>Here's what happens. When I run:</p>
<pre><code> result = db.command({
'findandmodify': 'my_collection',
'query': {'foo': 'bar'},
'update': {'... | 2 | 2010-02-28T05:54:21Z | 9,384,130 | <p>See PyMongo documentation:</p>
<blockquote>
<p>Note the order of keys in the command document is significant (the
âverbâ must come first), so commands which require multiple keys (e.g.
findandmodify) should use an instance of SON or a string and kwargs
instead of a Python dict.</p>
</blockquote>
<p><a ... | 1 | 2012-02-21T19:48:37Z | [
"python",
"mongodb",
"pymongo"
] |
Callback, observers, and asynch sockets in Python | 2,350,249 | <p>I'm still a neophyte Python programmer and I'm trying to do something that is a bit over my head.</p>
<p>What I've done is create a simple IRC bot using asyncore (and asynchronous sockets module). The client runs in a continuous loop, listening to the conversation in the channel. What I would like to do (I think?... | 0 | 2010-02-28T06:02:58Z | 2,350,274 | <p>While <code>Observer</code> is not a particularly popular DP (design pattern) in Python, it's not a totally "alien" one either, so if you're familiar with it, go right ahead. However, the normal way to call <code>observe</code> would be with <code>handler=self.log_join</code>, a callback that's actually a callable,... | 2 | 2010-02-28T06:16:10Z | [
"python",
"design-patterns",
"sockets",
"network-programming"
] |
Python Eval executing enviroment | 2,350,390 | <p>I do not understand what environment a eval or exec statement executes in. You can pass both global and local scopes to them but I don't quite understand what this means. Does python create an anonymous module for them, and if that is the case how do the global and local scope differ?</p>
<p>Does it run it like i... | 0 | 2010-02-28T07:17:09Z | 2,350,400 | <p>The "local" dictionary is where all names are being set during an <code>exec</code> or <code>eval</code>; the "global" one is used for lookup of names not found in the "local" one, but names aren't set there unless you're <code>exec</code>ing code that includes a <code>global</code> statement.</p>
<p>No module obje... | 2 | 2010-02-28T07:22:00Z | [
"python",
"eval",
"exec"
] |
Accessing a ServerFactory from the Service in Twisted | 2,350,394 | <p>I've been trying to come up with a decent design for multiple factories access each others information. For example, I have the following services: 1 management web service, a VirtualHost instance (multiple domains) and a built in DNS service. Going through the finger tutorial was very helpful but it lacks some key ... | 1 | 2010-02-28T07:19:18Z | 2,353,932 | <p>Well, after some help from a friend. I figured it out. If you create a multiservice, you can just pass the multiservice object to all your child services (I pass it in the init). Then you do setName('servicename'). Then from another service you can just get the information like so: x = self.multiService.getServiceNa... | 2 | 2010-03-01T04:55:58Z | [
"python",
"twisted"
] |
Parsing XML in Python using Expat | 2,350,494 | <p>Background: I'm coming from C#-land, so I'm looking for something like being able to handle nodes and values by selecting via Xpath. </p>
<p>Here's my code, so far:</p>
<pre><code>import urllib
import sys
from xml.parsers import expat
url = 'http://SomeWebService.SomeDomain.com'
u = urllib.urlopen(url)
Parser ... | 1 | 2010-02-28T08:15:09Z | 2,350,542 | <p>I think you would have more luck if you tried using one of the <code>xml.dom</code> packages, or <a href="http://docs.python.org/library/xml.etree.elementtree.html#module-xml.etree.ElementTree" rel="nofollow"><code>xml.etree.ElementTree</code></a>. ElementTree has some limited xpath support, so if that's what you're... | 1 | 2010-02-28T08:46:46Z | [
"python",
"xml",
"xpath",
"xmlnode",
"expat-parser"
] |
Date fields and Django's loaddata | 2,350,557 | <p>Can a date be loaded into a DateField using <a href="http://docs.djangoproject.com/en/dev/ref/django-admin/#loaddata-fixture-fixture" rel="nofollow">Django's loaddata admin</a> feature? I have a JSON file that I'm using to bulk load data into my app. When you dumpdata, date fields are outputted in the format <stro... | 0 | 2010-02-28T08:53:07Z | 2,357,365 | <p>Sounds like something else is broken, lupefiasco. Django has a pretty extensive set of tests to make sure you can dumpdata -> loaddata just fine.</p>
<p>Sounds like it may be a Ticket#5007 [http://code.djangoproject.com/ticket/5007], but it could just as well be one of many others. The error is after all rather vag... | 0 | 2010-03-01T16:39:56Z | [
"python",
"django",
"bulk-load"
] |
Django LowerCaseCharField | 2,350,681 | <p>We implemented a LowerCaseCharField. We would be happy to hear better implementation suggestions.</p>
<pre><code>from django.db.models.fields import CharField
class LowerCaseCharField(CharField):
"""
Defines a charfield which automatically converts all inputs to
lowercase and saves.
"""
def pr... | 11 | 2010-02-28T09:52:35Z | 2,350,726 | <p>You try making field_name a <a href="http://docs.python.org/library/functions.html#property" rel="nofollow">property</a> and do whatever in getter or setter.</p>
| 0 | 2010-02-28T10:16:13Z | [
"python",
"django",
"lowercase"
] |
Django LowerCaseCharField | 2,350,681 | <p>We implemented a LowerCaseCharField. We would be happy to hear better implementation suggestions.</p>
<pre><code>from django.db.models.fields import CharField
class LowerCaseCharField(CharField):
"""
Defines a charfield which automatically converts all inputs to
lowercase and saves.
"""
def pr... | 11 | 2010-02-28T09:52:35Z | 2,350,728 | <p>You may wish to override <code>to_python</code>, which will allow you to compare non-lowercase strings when doing database lookups. The actual method is <code>get_prep_value</code>, but as that calls <code>to_python</code> for <code>CharField</code>, it's more convenient to override that:</p>
<pre><code>def to_pyth... | 16 | 2010-02-28T10:17:00Z | [
"python",
"django",
"lowercase"
] |
Django LowerCaseCharField | 2,350,681 | <p>We implemented a LowerCaseCharField. We would be happy to hear better implementation suggestions.</p>
<pre><code>from django.db.models.fields import CharField
class LowerCaseCharField(CharField):
"""
Defines a charfield which automatically converts all inputs to
lowercase and saves.
"""
def pr... | 11 | 2010-02-28T09:52:35Z | 2,356,059 | <p>Using Python properties is not straightforward because of the way django.models.Models magically set their instance attributes based on class attributes. There is an <a href="http://code.djangoproject.com/ticket/3148" rel="nofollow">open bug</a> out for this.</p>
<p>I ended up doing exactly what the original poster... | 1 | 2010-03-01T13:28:41Z | [
"python",
"django",
"lowercase"
] |
Django LowerCaseCharField | 2,350,681 | <p>We implemented a LowerCaseCharField. We would be happy to hear better implementation suggestions.</p>
<pre><code>from django.db.models.fields import CharField
class LowerCaseCharField(CharField):
"""
Defines a charfield which automatically converts all inputs to
lowercase and saves.
"""
def pr... | 11 | 2010-02-28T09:52:35Z | 31,328,366 | <p>Another way to do it would be to add a <a href="https://docs.djangoproject.com/en/1.8/ref/signals/%23pre-save" rel="nofollow">pre_save</a> hook to your model, and then just convert all the fields you want to be lowercase to lowercase there using lower(). This is discussed <a href="http://stackoverflow.com/a/11922701... | 0 | 2015-07-09T21:15:35Z | [
"python",
"django",
"lowercase"
] |
memory location of dictionary in python 2.6.4 only? | 2,350,719 | <p>Is it possible to see a memory location/address of data dictionary in python 2.6.4 only??</p>
| 0 | 2010-02-28T10:12:53Z | 2,350,736 | <p>In CPython use <a href="http://docs.python.org/library/functions.html#id" rel="nofollow">id function</a>.</p>
| 2 | 2010-02-28T10:19:46Z | [
"python"
] |
Dictionary-like object in Python that allows setting arbitrary attributes | 2,350,817 | <p>What I want to do in my code:</p>
<pre><code>myobj = <SomeBuiltinClass>()
myobj.randomattr = 1
print myobj.randomattr
...
</code></pre>
<p>I can implement a custom SomeClass that implements <code>__setattr__</code> <code>__getattr__</code>.
But I wonder if there is already a built-in Python class or simple w... | 3 | 2010-02-28T10:52:51Z | 2,350,825 | <p>I like using the Bunch idiom for this. There are list of variations and some discussion <a href="http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/" rel="nofollow">here</a>.</p>
| 2 | 2010-02-28T10:57:51Z | [
"python",
"dictionary",
"attributes"
] |
Dictionary-like object in Python that allows setting arbitrary attributes | 2,350,817 | <p>What I want to do in my code:</p>
<pre><code>myobj = <SomeBuiltinClass>()
myobj.randomattr = 1
print myobj.randomattr
...
</code></pre>
<p>I can implement a custom SomeClass that implements <code>__setattr__</code> <code>__getattr__</code>.
But I wonder if there is already a built-in Python class or simple w... | 3 | 2010-02-28T10:52:51Z | 2,350,827 | <p>You can just use an empty class:</p>
<pre><code>class A(object): pass
a = A()
a.randomattr = 1
</code></pre>
| 7 | 2010-02-28T10:58:31Z | [
"python",
"dictionary",
"attributes"
] |
Dictionary-like object in Python that allows setting arbitrary attributes | 2,350,817 | <p>What I want to do in my code:</p>
<pre><code>myobj = <SomeBuiltinClass>()
myobj.randomattr = 1
print myobj.randomattr
...
</code></pre>
<p>I can implement a custom SomeClass that implements <code>__setattr__</code> <code>__getattr__</code>.
But I wonder if there is already a built-in Python class or simple w... | 3 | 2010-02-28T10:52:51Z | 5,741,595 | <p>One solution is to use mock's:</p>
<pre><code>from mock import Mock
myobj = Mock()
myobj.randomattr = 1
print myobj.randomattr
</code></pre>
<p>Second solution is to use namedtuple:</p>
<pre><code>from collections import namedtuple
myobj = namedtuple('MyObject', '')
myobj.randomattr = 1
print myobj.randomattr
</c... | 0 | 2011-04-21T08:37:17Z | [
"python",
"dictionary",
"attributes"
] |
literal usage of % in batch | 2,350,954 | <p>I have a batch file containing a python script using the Output template> %(NAME)s
when I ran it, cmd thinks its a var and igoners the %
so </p>
<pre><code>youtube-dl.py -b -o %(uploader)s-%(title)s-%(id)s.%(ext)s
</code></pre>
<p>turns into</p>
<pre><code>youtube-dl.py -b -o (uploader)s-(title)s-(id)s.(ext)s... | 2 | 2010-02-28T11:59:23Z | 2,350,967 | <p>Replace the % with %%:</p>
<pre><code>youtube-dl.py -b -o %%(uploader)s-%%(title)s-%%(id)s.%%(ext)s
</code></pre>
<p>(Note that, unlike on Unix, double quotes don't do a lot on Windows command lines.)</p>
| 3 | 2010-02-28T12:04:22Z | [
"python",
"cmd"
] |
literal usage of % in batch | 2,350,954 | <p>I have a batch file containing a python script using the Output template> %(NAME)s
when I ran it, cmd thinks its a var and igoners the %
so </p>
<pre><code>youtube-dl.py -b -o %(uploader)s-%(title)s-%(id)s.%(ext)s
</code></pre>
<p>turns into</p>
<pre><code>youtube-dl.py -b -o (uploader)s-(title)s-(id)s.(ext)s... | 2 | 2010-02-28T11:59:23Z | 2,350,995 | <p>If you don't want your <code>%</code> characters interpreted by cmd.exe, you should prefix them with the escape character:</p>
<pre><code>c:\> set qwert=55
c:\> echo %qwert%
55
c:\> echo ^%qwert^%
%qwert%
</code></pre>
| 3 | 2010-02-28T12:18:30Z | [
"python",
"cmd"
] |
literal usage of % in batch | 2,350,954 | <p>I have a batch file containing a python script using the Output template> %(NAME)s
when I ran it, cmd thinks its a var and igoners the %
so </p>
<pre><code>youtube-dl.py -b -o %(uploader)s-%(title)s-%(id)s.%(ext)s
</code></pre>
<p>turns into</p>
<pre><code>youtube-dl.py -b -o (uploader)s-(title)s-(id)s.(ext)s... | 2 | 2010-02-28T11:59:23Z | 2,351,013 | <p>here's an alternative suggestion you don't have to meddle with cmd "quirks" like that you encountered. Pass to your script normal text arguments, then in your script, do the templating.</p>
| 1 | 2010-02-28T12:23:11Z | [
"python",
"cmd"
] |
When will Jython support Python 3? | 2,351,008 | <p>According to <a href="http://wiki.python.org/jython/JythonFaq/GeneralInfo#IsJythonthesamelanguageasPython.3F">Jython's documentation</a>:</p>
<blockquote>
<p>Jython is an implementation of the
Python language for the Java platform.
Jython 2.5 implements the same
language as CPython 2.5, and nearly
all of ... | 38 | 2010-02-28T12:21:52Z | 2,351,038 | <p>Python 3 is still WAY to early for the community, people are waiting for it to be a bit more wide spread.</p>
| 0 | 2010-02-28T12:31:08Z | [
"python",
"python-3.x",
"jython"
] |
When will Jython support Python 3? | 2,351,008 | <p>According to <a href="http://wiki.python.org/jython/JythonFaq/GeneralInfo#IsJythonthesamelanguageasPython.3F">Jython's documentation</a>:</p>
<blockquote>
<p>Jython is an implementation of the
Python language for the Java platform.
Jython 2.5 implements the same
language as CPython 2.5, and nearly
all of ... | 38 | 2010-02-28T12:21:52Z | 2,351,358 | <p>Jython roadmap is definitely outdated.<br>
However, on Frank Wierzbicki's Weblog (one of Jython's main developers) you can get <a href="http://fwierzbicki.blogspot.com/2008/10/updated-jython-roadmap.html">an update</a>, telling that Python 3 is definitely on the radar.</p>
<p>Unfortunately, it is not yet clear when... | 25 | 2010-02-28T14:40:08Z | [
"python",
"python-3.x",
"jython"
] |
When will Jython support Python 3? | 2,351,008 | <p>According to <a href="http://wiki.python.org/jython/JythonFaq/GeneralInfo#IsJythonthesamelanguageasPython.3F">Jython's documentation</a>:</p>
<blockquote>
<p>Jython is an implementation of the
Python language for the Java platform.
Jython 2.5 implements the same
language as CPython 2.5, and nearly
all of ... | 38 | 2010-02-28T12:21:52Z | 33,433,803 | <p>5 years after the question has been asked, the answer is still "it will come, but the time frame for an initial release is not clear yet".</p>
<p>What we can say is that now there is a <a href="https://github.com/jython/jython3">jython3 repository</a> targetting Python 3.5. <code>README.md</code>, dated 28 May 2015... | 14 | 2015-10-30T10:28:12Z | [
"python",
"python-3.x",
"jython"
] |
Socket shutdown and rebind - How to avoid long wait? | 2,351,465 | <p>I'm working with socket in python, and being in development stage I need to kill and restart my program frequently.</p>
<p>The issue is that once killed my python script, I've to wait long time to be able to rebind the listen socket. Here's a snippet to reproduce the problem:</p>
<pre><code>#!/usr/bin/env python3 ... | 3 | 2010-02-28T15:15:37Z | 2,351,489 | <p>I'm not sure how to do it in Python, but you want to set the SO_REUSEADDR socket option.</p>
| 4 | 2010-02-28T15:22:01Z | [
"python",
"linux",
"sockets",
"python-3.x"
] |
python switch by class name? | 2,351,525 | <p>I am currently doing this, to do different things based on an object's type:</p>
<pre><code> actions = {
SomeClass: lambda: obj.name
AnotherClass: lambda: self.normalize(obj.identifier)
...[5 more of these]...
}
for a in actions.keys():
if isinstance(obj, a):
... | 2 | 2010-02-28T15:36:11Z | 2,351,536 | <p>What about</p>
<pre><code>actions[obj.__class__]()
</code></pre>
| 0 | 2010-02-28T15:40:10Z | [
"python",
"syntax",
"switch-statement"
] |
python switch by class name? | 2,351,525 | <p>I am currently doing this, to do different things based on an object's type:</p>
<pre><code> actions = {
SomeClass: lambda: obj.name
AnotherClass: lambda: self.normalize(obj.identifier)
...[5 more of these]...
}
for a in actions.keys():
if isinstance(obj, a):
... | 2 | 2010-02-28T15:36:11Z | 2,351,539 | <pre><code>actions[type(obj)]()
</code></pre>
| 0 | 2010-02-28T15:40:30Z | [
"python",
"syntax",
"switch-statement"
] |
python switch by class name? | 2,351,525 | <p>I am currently doing this, to do different things based on an object's type:</p>
<pre><code> actions = {
SomeClass: lambda: obj.name
AnotherClass: lambda: self.normalize(obj.identifier)
...[5 more of these]...
}
for a in actions.keys():
if isinstance(obj, a):
... | 2 | 2010-02-28T15:36:11Z | 2,351,543 | <pre><code>actions[obj.__class__]()
</code></pre>
<p>works if <code>obj</code> is really an instance of (say) <code>SomeClass</code> and not of a subclass -- so if that can be the case, the result will be different from your current way of handling it. Also note that this might raise a <code>KeyError</code> if the cla... | 1 | 2010-02-28T15:41:43Z | [
"python",
"syntax",
"switch-statement"
] |
python switch by class name? | 2,351,525 | <p>I am currently doing this, to do different things based on an object's type:</p>
<pre><code> actions = {
SomeClass: lambda: obj.name
AnotherClass: lambda: self.normalize(obj.identifier)
...[5 more of these]...
}
for a in actions.keys():
if isinstance(obj, a):
... | 2 | 2010-02-28T15:36:11Z | 2,351,554 | <pre><code>results = [func() for cls, func in actions.iteritems() if isinstance(obj, cls)]
</code></pre>
<p>There will be zero or more results, if your object <code>isinstance</code> of zero or more of the class-keys. </p>
<p>Using <code>type(obj)</code> as key will only work if your object is of that type. If it's f... | 0 | 2010-02-28T15:44:34Z | [
"python",
"syntax",
"switch-statement"
] |
python switch by class name? | 2,351,525 | <p>I am currently doing this, to do different things based on an object's type:</p>
<pre><code> actions = {
SomeClass: lambda: obj.name
AnotherClass: lambda: self.normalize(obj.identifier)
...[5 more of these]...
}
for a in actions.keys():
if isinstance(obj, a):
... | 2 | 2010-02-28T15:36:11Z | 2,351,558 | <pre><code>class SomeClass( object ):
....
def action( self ):
return self.name
class AnotherClass( object ):
....
def action( self ):
return self.normalize( self.identifier )
[5 more classes like the above two]
a.action()
</code></pre>
<p>Simpler. Clearer. More extensible. Less Magic. N... | 6 | 2010-02-28T15:45:28Z | [
"python",
"syntax",
"switch-statement"
] |
python switch by class name? | 2,351,525 | <p>I am currently doing this, to do different things based on an object's type:</p>
<pre><code> actions = {
SomeClass: lambda: obj.name
AnotherClass: lambda: self.normalize(obj.identifier)
...[5 more of these]...
}
for a in actions.keys():
if isinstance(obj, a):
... | 2 | 2010-02-28T15:36:11Z | 2,351,563 | <p>I assume you have a parent class for all of those, or at least a mixin. Put a default return function in the parent or mixin, and then override it in those that are different... It's the only proper way of doing it. </p>
<p>Sure, it makes extra code, but at least it's encapsulated, and scalable. Say you wanna add s... | 1 | 2010-02-28T15:47:35Z | [
"python",
"syntax",
"switch-statement"
] |
Controlling distutils from Scons | 2,351,553 | <p>I have a C++ library that I build using Scons which is eventually linked into (among other things) a Python extension.</p>
<p>Once I have built the library with scons, I have written a standard setup.py script which I call to build and install the extension.</p>
<p>My main problem is that setup.py does not recogni... | 4 | 2010-02-28T15:44:31Z | 2,352,925 | <p>You can do any command line from SCons. See <a href="http://scons.org/doc/1.2.0/HTML/scons-user/c3427.html" rel="nofollow">Writing Your Own Builders</a>. Then, you can detect any changes for a given file format by <a href="http://scons.org/doc/1.2.0/HTML/scons-user/c3755.html" rel="nofollow">writing a scanner</a>... | 1 | 2010-02-28T22:24:17Z | [
"python",
"scons",
"distutils"
] |
Controlling distutils from Scons | 2,351,553 | <p>I have a C++ library that I build using Scons which is eventually linked into (among other things) a Python extension.</p>
<p>Once I have built the library with scons, I have written a standard setup.py script which I call to build and install the extension.</p>
<p>My main problem is that setup.py does not recogni... | 4 | 2010-02-28T15:44:31Z | 2,354,205 | <p>I have successfully created SConstruct to compile extensions for Python written in Pyrex. The main idea is to get appropriate C-compiler flags from distutils and then setup your Environment.</p>
<p>Check this pages on scons wiki:</p>
<ul>
<li><a href="http://www.scons.org/wiki/PythonExtensions" rel="nofollow">http... | 0 | 2010-03-01T06:24:51Z | [
"python",
"scons",
"distutils"
] |
What are the Difference between cElementtree and ElementTree? | 2,351,694 | <p>I know a little of dom, and would like to learn about ElementTree. Python 2.6 has a somewhat older implementation of ElementTree, but still usable. However, it looks like it comes with two different classes: xml.etree.ElementTree and xml.etree.cElementTree. Would someone please be so kind to enlighten me with their ... | 8 | 2010-02-28T16:32:11Z | 2,351,704 | <p>From <a href="http://effbot.org/zone/celementtree.htm">http://effbot.org/zone/celementtree.htm</a>:</p>
<blockquote>
<p>The cElementTree module is a C implementation of the ElementTree API, optimized for fast parsing and low memory use. On typical documents, cElementTree is 15-20 times faster than the Python vers... | 5 | 2010-02-28T16:35:46Z | [
"python",
"xml"
] |
What are the Difference between cElementtree and ElementTree? | 2,351,694 | <p>I know a little of dom, and would like to learn about ElementTree. Python 2.6 has a somewhat older implementation of ElementTree, but still usable. However, it looks like it comes with two different classes: xml.etree.ElementTree and xml.etree.cElementTree. Would someone please be so kind to enlighten me with their ... | 8 | 2010-02-28T16:32:11Z | 2,351,707 | <p>It is the same library (same API, same features) but ElementTree is implemented in Python and cElementTree is implemented in C.</p>
<p>If you can, use the C implementation because it is optimized for fast parsing and low memory use, and is 15-20 times faster than the Python implementation.</p>
<p>Use the Python ve... | 16 | 2010-02-28T16:36:10Z | [
"python",
"xml"
] |
What are the Difference between cElementtree and ElementTree? | 2,351,694 | <p>I know a little of dom, and would like to learn about ElementTree. Python 2.6 has a somewhat older implementation of ElementTree, but still usable. However, it looks like it comes with two different classes: xml.etree.ElementTree and xml.etree.cElementTree. Would someone please be so kind to enlighten me with their ... | 8 | 2010-02-28T16:32:11Z | 2,351,710 | <p>ElementTree is implemented in python while cElementTree is implemented in C. Thus cElementTree will be faster, but also not available where you don't have access to C, such as in Jython or IronPython or on Google App Engine.</p>
<p>Functionally, they should be equivalent.</p>
| 4 | 2010-02-28T16:36:47Z | [
"python",
"xml"
] |
App Engine (Python) Datastore Precall API Hooks | 2,351,752 | <p><strong>Background</strong></p>
<p>So let's say I'm making app for GAE, and I want to use <a href="http://code.google.com/appengine/articles/hooks.html" rel="nofollow">API Hooks</a>.</p>
<p><em>BIG EDIT</em>: In the original version of this question, I described my use case, but some folks correctly pointed out th... | 5 | 2010-02-28T16:50:34Z | 2,352,045 | <p>I don't think that Hooks are really going to solve this problem. The Hooks will only run in the context of your AppEngine application, but the user can change their nickname outside of your application using Google Account settings. If they do that, it won't trigger any logic implement in your hooks.</p>
<p>I think... | 1 | 2010-02-28T18:18:33Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
App Engine (Python) Datastore Precall API Hooks | 2,351,752 | <p><strong>Background</strong></p>
<p>So let's say I'm making app for GAE, and I want to use <a href="http://code.google.com/appengine/articles/hooks.html" rel="nofollow">API Hooks</a>.</p>
<p><em>BIG EDIT</em>: In the original version of this question, I described my use case, but some folks correctly pointed out th... | 5 | 2010-02-28T16:50:34Z | 2,353,041 | <p>Hooks are a little low level for the task at hand. What you probably want is a custom property class. DerivedProperty, from <a href="http://github.com/arachnid/aetycoon" rel="nofollow">aetycoon</a>, is just the ticket.</p>
<p>Bear in mind, however, that the 'nickname' field of the user object is probably not what y... | 2 | 2010-02-28T22:55:58Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
App Engine (Python) Datastore Precall API Hooks | 2,351,752 | <p><strong>Background</strong></p>
<p>So let's say I'm making app for GAE, and I want to use <a href="http://code.google.com/appengine/articles/hooks.html" rel="nofollow">API Hooks</a>.</p>
<p><em>BIG EDIT</em>: In the original version of this question, I described my use case, but some folks correctly pointed out th... | 5 | 2010-02-28T16:50:34Z | 6,090,580 | <p>The issue here is that within the context of the <code>hook()</code> function an <code>entity</code> is not an instance of db.Model as you are expecting. </p>
<p>In this context <code>entity</code> is the protocol buffer class confusingly referred to as entity (<a href="http://code.google.com/p/googleappengine/sour... | 2 | 2011-05-22T20:28:52Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
numpy.matrix manipulations | 2,351,844 | <p>I have a question about numpy.matrix class. How can I perform such basic manipulations with matrices as adding, deleting and replacing rows and columns?</p>
<p>p.s. I apologize for the lame question..</p>
| 0 | 2010-02-28T17:20:40Z | 2,351,868 | <p>Perfectly fine question! Try examining this code:</p>
<pre><code>import scipy
X = scipy.rand(3,3)
Y = scipy.rand(3,3)
print X+Y
print scipy.delete(X, 1, 0)
print scipy.delete(X, 1, 1)
X[1,:] = [1,2,3]
print X
</code></pre>
<p>For more, see the numpy/scipy docs here: <a href="http://docs.scipy.org/" rel="nofollow">... | 3 | 2010-02-28T17:30:18Z | [
"python",
"matrix",
"numpy"
] |
How can I prevent a name error error in python? | 2,351,904 | <p>When I run my program core.py (<a href="http://pastebin.com/kbzbBUYd" rel="nofollow">http://pastebin.com/kbzbBUYd</a>) it returns:</p>
<p>File "core.py", line 47, in texto
core.mail(numbersendlist, messagetext)
NameError: global name 'core' is not defined</p>
<p>Can anyone tell me what is going on and how I ca... | 1 | 2010-02-28T17:41:18Z | 2,351,926 | <p><code>core</code> is not a name that you've defined, yet. I expect that you intended to write something like</p>
<pre><code>core = Core('username', 'password')
</code></pre>
<p>before calling <code>texto</code>?</p>
| 1 | 2010-02-28T17:47:50Z | [
"python"
] |
How can I prevent a name error error in python? | 2,351,904 | <p>When I run my program core.py (<a href="http://pastebin.com/kbzbBUYd" rel="nofollow">http://pastebin.com/kbzbBUYd</a>) it returns:</p>
<p>File "core.py", line 47, in texto
core.mail(numbersendlist, messagetext)
NameError: global name 'core' is not defined</p>
<p>Can anyone tell me what is going on and how I ca... | 1 | 2010-02-28T17:41:18Z | 2,351,928 | <p>You're getting <code>NameError</code> Because there's no such name <code>core</code> defined in your code in either local or global scope. Create a <code>Core</code> object first before calling it's methods.</p>
<p>Also the indentation of <code>texto()</code> is probably wrong. You won't be able to use this functio... | 5 | 2010-02-28T17:48:21Z | [
"python"
] |
Python error: ImportError: cannot import name Akismet | 2,351,919 | <p>I've seen many similar errors, but I can't see a solution that applies to my particular problem.</p>
<p>I'm trying to use the <a href="http://www.voidspace.org.uk/python/akismet_python.html#downloading">Akismet module</a> which is on my PYTHONPATH, then if I start up the interactive interpreter, when I run <code>f... | 11 | 2010-02-28T17:46:20Z | 2,351,940 | <p>It will work perfectly if your PYTHONPATH is set correctly and globally (just tested it myself).</p>
<ul>
<li>Must be set to the directory containing "akismet.py", not the file path! Make sure you don't use relative paths.</li>
<li>Note that you might need to reboot/logoff in order to apply environment variable cha... | 5 | 2010-02-28T17:51:48Z | [
"python",
"environment-variables",
"python-import"
] |
Python error: ImportError: cannot import name Akismet | 2,351,919 | <p>I've seen many similar errors, but I can't see a solution that applies to my particular problem.</p>
<p>I'm trying to use the <a href="http://www.voidspace.org.uk/python/akismet_python.html#downloading">Akismet module</a> which is on my PYTHONPATH, then if I start up the interactive interpreter, when I run <code>f... | 11 | 2010-02-28T17:46:20Z | 2,351,942 | <p>You should have the directory containing the 'akismet' directory in your path. I guess, you have added the 'akismet' directory itself to $PYTHONPATH. </p>
<p>When you write:</p>
<pre><code>from akismet import Akismet
</code></pre>
<p>Python tries to open file <code>akismet/Akismet.py</code> somewhere in its sear... | 2 | 2010-02-28T17:52:00Z | [
"python",
"environment-variables",
"python-import"
] |
Python error: ImportError: cannot import name Akismet | 2,351,919 | <p>I've seen many similar errors, but I can't see a solution that applies to my particular problem.</p>
<p>I'm trying to use the <a href="http://www.voidspace.org.uk/python/akismet_python.html#downloading">Akismet module</a> which is on my PYTHONPATH, then if I start up the interactive interpreter, when I run <code>f... | 11 | 2010-02-28T17:46:20Z | 2,351,948 | <p>Check if your PYTHONPATH is really what you expect it to be, e.g. by doing this in an interactive console:</p>
<pre><code>In [1]: import sys
In [2]: print sys.path
</code></pre>
<p>is akismet.py really in one of those folders?</p>
| 4 | 2010-02-28T17:53:39Z | [
"python",
"environment-variables",
"python-import"
] |
Python error: ImportError: cannot import name Akismet | 2,351,919 | <p>I've seen many similar errors, but I can't see a solution that applies to my particular problem.</p>
<p>I'm trying to use the <a href="http://www.voidspace.org.uk/python/akismet_python.html#downloading">Akismet module</a> which is on my PYTHONPATH, then if I start up the interactive interpreter, when I run <code>f... | 11 | 2010-02-28T17:46:20Z | 7,460,739 | <p>I just want to draw more attention to Doppelganger's own answer to his question. I had this error, and the situation is this:</p>
<p>You're trying to import function/class X from a module called say 'strategy.py'.</p>
<p>Unfortunately you've also created a python package directory called strategy, in other words ... | 15 | 2011-09-18T09:56:30Z | [
"python",
"environment-variables",
"python-import"
] |
Python error: ImportError: cannot import name Akismet | 2,351,919 | <p>I've seen many similar errors, but I can't see a solution that applies to my particular problem.</p>
<p>I'm trying to use the <a href="http://www.voidspace.org.uk/python/akismet_python.html#downloading">Akismet module</a> which is on my PYTHONPATH, then if I start up the interactive interpreter, when I run <code>f... | 11 | 2010-02-28T17:46:20Z | 14,308,152 | <p>Simple:</p>
<ol>
<li>Make sure you have installed akismet (system-wide or virtualenv)</li>
<li>Verify by pasting (import akismet) into a python shell</li>
<li>CD into the root directory of your project and run (<strong>find . -name akismet.py</strong>)</li>
<li>If you find a file with that name, see if you can rena... | 1 | 2013-01-13T21:05:46Z | [
"python",
"environment-variables",
"python-import"
] |
Python error: ImportError: cannot import name Akismet | 2,351,919 | <p>I've seen many similar errors, but I can't see a solution that applies to my particular problem.</p>
<p>I'm trying to use the <a href="http://www.voidspace.org.uk/python/akismet_python.html#downloading">Akismet module</a> which is on my PYTHONPATH, then if I start up the interactive interpreter, when I run <code>f... | 11 | 2010-02-28T17:46:20Z | 16,020,535 | <p>I always forget that <strong>ipython</strong> imports the modules when you use <code>run</code> command inside the ipython interpreter. It won't re-import any modules that you change, so any new variables or functions won't be found. This is a <a href="https://github.com/ipython/ipython/issues/461" rel="nofollow">kn... | 0 | 2013-04-15T16:47:41Z | [
"python",
"environment-variables",
"python-import"
] |
What's the proper way to describe an associative object by SQLalchemy the declarative way | 2,351,927 | <p>I'm looking for a way to describe an associative object the declarative way. Beyond storing the foreign keys in the association table, I need to store information like the creation date of the association.</p>
<p>Today, my model looks like that :</p>
<pre><code># Define the User class
class User(Base):
__table... | 2 | 2010-02-28T17:47:53Z | 2,351,967 | <p>As you can see in <a href="http://www.sqlalchemy.org/docs/05/reference/ext/declarative.html#configuring-relations" rel="nofollow">the manual</a>, configuring a one to many relation is really simple:</p>
<pre><code>class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = C... | 0 | 2010-02-28T17:57:40Z | [
"python",
"sqlalchemy"
] |
What's the proper way to describe an associative object by SQLalchemy the declarative way | 2,351,927 | <p>I'm looking for a way to describe an associative object the declarative way. Beyond storing the foreign keys in the association table, I need to store information like the creation date of the association.</p>
<p>Today, my model looks like that :</p>
<pre><code># Define the User class
class User(Base):
__table... | 2 | 2010-02-28T17:47:53Z | 2,351,999 | <p>What you are using at the moment is just a Many-to-Many-relation. How to work with association objects is described in the <a href="http://www.sqlalchemy.org/docs/mappers.html#association-object" rel="nofollow">docs</a>.</p>
<p>There is also an extension called <a href="http://www.sqlalchemy.org/docs/reference/ext/... | 1 | 2010-02-28T18:06:52Z | [
"python",
"sqlalchemy"
] |
Detect when threads are running in a python application? | 2,351,989 | <p>How can we detect when threads are running in a python application?</p>
<p>Motivation: We were recently debugging a large Python application that had several customer supplied modules that were supplied without source code. Unbeknowst to us (and our customer!), one of these modules would launch threads under very s... | 6 | 2010-02-28T18:04:27Z | 2,352,229 | <h2>Debugger</h2>
<p>Usually a debugger can show you all the threads and what each one is executing. If you tell us which debugger you are using, someone can tell you how to see the thread info. If you aren't using a debugger, I highly suggest you start. Debugging multi-threaded programs without a real debugger is qui... | 6 | 2010-02-28T19:03:35Z | [
"python",
"multithreading"
] |
Can't use unichr in Python 3.1 | 2,352,018 | <p>new here! I'm a beginner in Python, and I've been looking through the <strong>Python Cookbook (2nd Edition)</strong> to learn how to process strings and characters. </p>
<p>I wanted to try converting a number into its Unicode equivalent. So I tried using the <a href="http://docs.python.org/library/functions.html">b... | 11 | 2010-02-28T18:11:55Z | 2,352,047 | <p>In Python 3, you just use chr:</p>
<pre><code>>>> chr(10000)
'â'
</code></pre>
| 22 | 2010-02-28T18:19:08Z | [
"python",
"unicode",
"string"
] |
Can't use unichr in Python 3.1 | 2,352,018 | <p>new here! I'm a beginner in Python, and I've been looking through the <strong>Python Cookbook (2nd Edition)</strong> to learn how to process strings and characters. </p>
<p>I wanted to try converting a number into its Unicode equivalent. So I tried using the <a href="http://docs.python.org/library/functions.html">b... | 11 | 2010-02-28T18:11:55Z | 2,352,050 | <p>Python 3.x doesn't have a special Unicode string type/class. Every string is a Unicode string. So... I'd try <code>chr</code>. Should give you what <code>unichr</code> did pre-3.x. Can't test, sadly.</p>
| 1 | 2010-02-28T18:19:43Z | [
"python",
"unicode",
"string"
] |
Can't use unichr in Python 3.1 | 2,352,018 | <p>new here! I'm a beginner in Python, and I've been looking through the <strong>Python Cookbook (2nd Edition)</strong> to learn how to process strings and characters. </p>
<p>I wanted to try converting a number into its Unicode equivalent. So I tried using the <a href="http://docs.python.org/library/functions.html">b... | 11 | 2010-02-28T18:11:55Z | 2,352,059 | <p>In Python 3, there's no difference between unicode and normal strings anymore. Only between unicode strings and binary data. So the developers finally removed the <code>unichr</code> function in favor of a common <code>chr</code> which now does what the old <code>unichr</code> did. See the documentation <a href="htt... | 7 | 2010-02-28T18:21:23Z | [
"python",
"unicode",
"string"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.