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
which is the best way to get the value of 'session_key','uid','expires'
2,330,857
<p>i have a string </p> <p>''' {"session_key":"3.KbRiifBOxY_0ouPag6__.3600.1267063200-16423986","uid":164 23386,"expires":12673200,"secret":"sm7WM_rRtjzXeOT_jDoQ__","sig":"6a6aeb66 64a1679bbeed4282154b35"} '''</p> <p>how to get the value .</p> <p>thanks</p>
1
2010-02-25T01:00:55Z
2,330,884
<p>For a simple-to-code method, I suggest using <code>ast.parse()</code> or <code>eval()</code> to create a dictionary from your string, and then accessing the fields as usual. The difference between the two functions above is that <code>ast.parse</code> can only evaluate base types, and is therefore more secure if som...
0
2010-02-25T01:08:13Z
[ "python" ]
Why am I getting no attribute '__getitem__' error for dictionary?
2,331,015
<p>Why am I getting no attribute <code>__getitem__</code> error for dictionary:</p> <pre><code>Traceback (most recent call last): File "./thumbnail.py", line 39, in &lt;module&gt; main() File "./thumbnail.py", line 19, in main options['input_pattern'] AttributeError: Values instance has no attribute '__get...
14
2010-02-25T01:43:58Z
2,331,026
<p><code>options</code> is not a dict:</p> <pre><code>print options.input_pattern </code></pre>
23
2010-02-25T01:47:01Z
[ "python", "dictionary", "optparse" ]
Why am I getting no attribute '__getitem__' error for dictionary?
2,331,015
<p>Why am I getting no attribute <code>__getitem__</code> error for dictionary:</p> <pre><code>Traceback (most recent call last): File "./thumbnail.py", line 39, in &lt;module&gt; main() File "./thumbnail.py", line 19, in main options['input_pattern'] AttributeError: Values instance has no attribute '__get...
14
2010-02-25T01:43:58Z
3,120,306
<p>If you must have a dict, use </p> <pre><code>options.__dict__ </code></pre>
7
2010-06-25T18:05:00Z
[ "python", "dictionary", "optparse" ]
Why am I getting no attribute '__getitem__' error for dictionary?
2,331,015
<p>Why am I getting no attribute <code>__getitem__</code> error for dictionary:</p> <pre><code>Traceback (most recent call last): File "./thumbnail.py", line 39, in &lt;module&gt; main() File "./thumbnail.py", line 19, in main options['input_pattern'] AttributeError: Values instance has no attribute '__get...
14
2010-02-25T01:43:58Z
31,789,785
<p>As another user said, options is not a dictionary. I made this mistake myself. If I have an option <code>--file FILE</code></p> <p>Then I can call </p> <p><code>option.file</code></p> <p>which returns FILE. It's that easy!</p>
0
2015-08-03T14:21:56Z
[ "python", "dictionary", "optparse" ]
piping output of subprocess.Popen to files
2,331,339
<p>I need to launch a number of long-running processes with <code>subprocess.Popen</code>, and would like to have the <code>stdout</code> and <code>stderr</code> from each automatically piped to separate log files. Each process will run simultaneously for several minutes, and I want two log files (<code>stdout</code> a...
30
2010-02-25T03:08:15Z
2,331,376
<p>You can pass <code>stdout</code> and <code>stderr</code> as parameters to <code>Popen()</code></p> <pre><code>subprocess.Popen(self, args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_...
38
2010-02-25T03:16:44Z
[ "python", "subprocess", "stdout" ]
piping output of subprocess.Popen to files
2,331,339
<p>I need to launch a number of long-running processes with <code>subprocess.Popen</code>, and would like to have the <code>stdout</code> and <code>stderr</code> from each automatically piped to separate log files. Each process will run simultaneously for several minutes, and I want two log files (<code>stdout</code> a...
30
2010-02-25T03:08:15Z
2,331,379
<p>Per <a href="http://docs.python.org/library/subprocess.html?highlight=popen#subprocess.Popen">the docs</a>,</p> <blockquote> <p>stdin, stdout and stderr specify the executed programs’ standard input, standard output and standard error file handles, respectively. Valid values are PIPE, an existing file ...
26
2010-02-25T03:18:00Z
[ "python", "subprocess", "stdout" ]
piping output of subprocess.Popen to files
2,331,339
<p>I need to launch a number of long-running processes with <code>subprocess.Popen</code>, and would like to have the <code>stdout</code> and <code>stderr</code> from each automatically piped to separate log files. Each process will run simultaneously for several minutes, and I want two log files (<code>stdout</code> a...
30
2010-02-25T03:08:15Z
3,773,691
<p>I am simultaneously running two subprocesses, and saving the output from both into a single log file. I have also built in a timeout to handle hung subprocesses. When the output gets too big, the timeout always triggers, and none of the stdout from either subprocess gets saved to the log file. The answer posed by Al...
1
2010-09-22T21:15:21Z
[ "python", "subprocess", "stdout" ]
datetime.datetime.utcnow() why no tzinfo?
2,331,592
<pre><code>datetime.datetime.utcnow() datetime.datetime(2010, 2, 25, 4, 14, 37, 366086) </code></pre> <p>Why does this datetime not have any tz info say its a utc date.</p>
115
2010-02-25T04:14:00Z
2,331,594
<p>UTC dates don't need any timezone info since they're UTC, which by definition means that they have no offset.</p>
-9
2010-02-25T04:15:54Z
[ "python", "datetime" ]
datetime.datetime.utcnow() why no tzinfo?
2,331,592
<pre><code>datetime.datetime.utcnow() datetime.datetime(2010, 2, 25, 4, 14, 37, 366086) </code></pre> <p>Why does this datetime not have any tz info say its a utc date.</p>
115
2010-02-25T04:14:00Z
2,331,635
<p>The standard Python libraries don't include any tzinfo classes (but <a href="https://www.python.org/dev/peps/pep-0431/">see pep 431</a>). I can only guess at the reasons. Personally I think it was a mistake not to include a tzinfo class for UTC, because that one is uncontroversial enough to have a standard implement...
36
2010-02-25T04:27:46Z
[ "python", "datetime" ]
datetime.datetime.utcnow() why no tzinfo?
2,331,592
<pre><code>datetime.datetime.utcnow() datetime.datetime(2010, 2, 25, 4, 14, 37, 366086) </code></pre> <p>Why does this datetime not have any tz info say its a utc date.</p>
115
2010-02-25T04:14:00Z
2,331,640
<p>That means it is timezone naive, so you can't use it with <code>datetime.astimezone</code></p> <p>you can give it a timezone like this</p> <pre><code>import pytz # 3rd party: $ pip install pytz u = datetime.utcnow() u = u.replace(tzinfo=pytz.utc) #NOTE: it works only with a fixed utc offset </code></pre> <p>now...
101
2010-02-25T04:28:53Z
[ "python", "datetime" ]
datetime.datetime.utcnow() why no tzinfo?
2,331,592
<pre><code>datetime.datetime.utcnow() datetime.datetime(2010, 2, 25, 4, 14, 37, 366086) </code></pre> <p>Why does this datetime not have any tz info say its a utc date.</p>
115
2010-02-25T04:14:00Z
19,839,238
<p>The <code>pytz</code> module is one option, and there is another <code>python-dateutil</code>, which although is also third party package, may already be available depending on your other dependencies and operating system.</p> <p>I just wanted to include this methodology for reference- if you've already installed <...
15
2013-11-07T15:03:14Z
[ "python", "datetime" ]
datetime.datetime.utcnow() why no tzinfo?
2,331,592
<pre><code>datetime.datetime.utcnow() datetime.datetime(2010, 2, 25, 4, 14, 37, 366086) </code></pre> <p>Why does this datetime not have any tz info say its a utc date.</p>
115
2010-02-25T04:14:00Z
24,666,683
<p>Note that for Python 3.2 onwards, the <code>datetime</code> module contains <code>datetime.timezone</code>. The documentation for <a href="https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow"><code>datetime.utcnow()</code></a> says:</p> <blockquote> <p>An aware current UTC datetime can be obt...
25
2014-07-10T02:43:55Z
[ "python", "datetime" ]
datetime.datetime.utcnow() why no tzinfo?
2,331,592
<pre><code>datetime.datetime.utcnow() datetime.datetime(2010, 2, 25, 4, 14, 37, 366086) </code></pre> <p>Why does this datetime not have any tz info say its a utc date.</p>
115
2010-02-25T04:14:00Z
25,004,676
<pre><code>from datetime import datetime from dateutil.relativedelta import relativedelta d = datetime.now() date = datetime.isoformat(d).split('.')[0] d_month = datetime.today() + relativedelta(months=1) next_month = datetime.isoformat(d_month).split('.')[0] </code></pre>
-4
2014-07-28T21:29:25Z
[ "python", "datetime" ]
datetime.datetime.utcnow() why no tzinfo?
2,331,592
<pre><code>datetime.datetime.utcnow() datetime.datetime(2010, 2, 25, 4, 14, 37, 366086) </code></pre> <p>Why does this datetime not have any tz info say its a utc date.</p>
115
2010-02-25T04:14:00Z
32,465,200
<p>Julien Danjou wrote a good article explaining <a href="https://julien.danjou.info/blog/2015/python-and-timezones">why you should never deal with timezones</a>. An excerpt:</p> <blockquote> <p>Indeed, Python datetime API always returns unaware datetime objects, which is very unfortunate. Indeed, as soon as you g...
6
2015-09-08T18:53:36Z
[ "python", "datetime" ]
How to set a icon file while creating file
2,331,690
<p>I am creating a tar file ( from several files), now while saving this tar file i save this file as my particular extension like (.xyz), so i want whenever i save this type file (.xyz extension) from my tool this file should save with a particular ico file format. This is similar like when we save a bmp or jpeg file ...
1
2010-02-25T04:40:59Z
2,332,210
<p>To associate a icon with your extension you will have to create a registry entry for that and a icon associated with a extension doesn't mean anything unless you associate some program to open it with you, that too you can do in registry e.g</p> <ol> <li><p>Create an entry for your program's icon name, e.g. HKCU\S...
1
2010-02-25T06:54:52Z
[ "python", "wxpython" ]
A user management system for a new app?
2,331,699
<p>im using python. is there a widely accepted way of doing it? it deals with some data management things, so i dont want to implement it like in stackoverflow, with anonymous accounts. i also don't want to roll my own system from scratch. any recommendations?</p>
0
2010-02-25T04:45:48Z
2,331,787
<p>Are you talking about a <em>web</em> application? If so, <a href="http://openid.net/" rel="nofollow">OpenId</a> is probably the way to go, and <a href="http://openidenabled.com/python-openid/" rel="nofollow">this library</a> probably the most popular way to implement it in Python. If you're talking about user mana...
1
2010-02-25T05:11:06Z
[ "python", "language-agnostic" ]
Android app uploading data to a python server via post
2,331,862
<p>I have successfully implemented this from android to a java httpservlet on google app engine, but I'd like to use python instead for the server side. I'm new to python. Has anyone done this? I have the guestbook example up and running, but I can't seem to send posts from my android app to the server. </p> <p>I'd al...
1
2010-02-25T05:33:11Z
3,407,420
<p>I know it's been a long time. But I did solve this so I'll post the solution. </p> <p>Android code:</p> <pre><code> url = new URL(SERVER_URL); URLConnection connection = url.openConnection(); connection.setDoOutput(true); OutputStreamWriter out = new OutputStreamWriter( ...
2
2010-08-04T16:01:03Z
[ "java", "python", "http", "google-app-engine", "post" ]
Modify excel file in python on linux enviroment
2,331,916
<p>how do i insert few row in an existing excel file using python? the excel file maybe be of any excel version. On windows that could have been possible by using win32com.client...but i need to make the changes in the linux environment. how can i do it?</p>
1
2010-02-25T05:44:38Z
2,331,998
<p>you can use <a href="http://pypi.python.org/pypi/pyExcelerator/" rel="nofollow">pyExcelerator</a>. the package comes with example demos to write excel files</p>
2
2010-02-25T06:05:39Z
[ "python", "linux", "excel" ]
Modify excel file in python on linux enviroment
2,331,916
<p>how do i insert few row in an existing excel file using python? the excel file maybe be of any excel version. On windows that could have been possible by using win32com.client...but i need to make the changes in the linux environment. how can i do it?</p>
1
2010-02-25T05:44:38Z
10,111,666
<p>I'm looking into this myself and found <a href="https://bitbucket.org/ericgazoni/openpyxl/wiki/Home" rel="nofollow">https://bitbucket.org/ericgazoni/openpyxl/wiki/Home</a> . It is a new library that allows editing xlsx files.</p>
0
2012-04-11T18:18:47Z
[ "python", "linux", "excel" ]
How to decode JSON with Python
2,331,943
<p>I'm getting my JSON from reddit.com, essentially <a href="http://www.reddit.com/.json">something like this.</a> I have done quite a bit of reading, but I don't really understand how I can grab the information I want from this JSON (I want a list of the story links). I understand that I can "decode" the JSON into a d...
19
2010-02-25T05:51:01Z
2,331,958
<p>If you're using Python 2.6 or later, use the built-in <a href="http://docs.python.org/library/json.html"><code>json</code></a> library. Otherwise, use <a href="http://code.google.com/p/simplejson/"><code>simplejson</code></a> which has exactly the same interface.</p> <p>You can do this adaptively without having to ...
22
2010-02-25T05:54:25Z
[ "python", "json" ]
How to decode JSON with Python
2,331,943
<p>I'm getting my JSON from reddit.com, essentially <a href="http://www.reddit.com/.json">something like this.</a> I have done quite a bit of reading, but I don't really understand how I can grab the information I want from this JSON (I want a list of the story links). I understand that I can "decode" the JSON into a d...
19
2010-02-25T05:51:01Z
2,331,962
<p>I assume that you would parse the data into a dictionary and then extract the relevant bits from it.</p> <p>You can parse json in python using appropriate <a href="http://docs.python.org/library/json.html" rel="nofollow">python library</a> </p>
0
2010-02-25T05:54:41Z
[ "python", "json" ]
How to decode JSON with Python
2,331,943
<p>I'm getting my JSON from reddit.com, essentially <a href="http://www.reddit.com/.json">something like this.</a> I have done quite a bit of reading, but I don't really understand how I can grab the information I want from this JSON (I want a list of the story links). I understand that I can "decode" the JSON into a d...
19
2010-02-25T05:51:01Z
2,331,967
<pre><code>import urllib2 import json u = urllib2.urlopen('http://www.reddit.com/.json') print json.load(u) u.close() </code></pre>
13
2010-02-25T05:55:53Z
[ "python", "json" ]
How to decode JSON with Python
2,331,943
<p>I'm getting my JSON from reddit.com, essentially <a href="http://www.reddit.com/.json">something like this.</a> I have done quite a bit of reading, but I don't really understand how I can grab the information I want from this JSON (I want a list of the story links). I understand that I can "decode" the JSON into a d...
19
2010-02-25T05:51:01Z
32,429,662
<p>There are two ways you can "decode" json with Python, <em>after</em> you've parsed it into dicts and lists with the json library. </p> <p>First, accessing it by indexes, like this:</p> <pre><code>url_list = [t['entries'][0]['url'] for t in data['windows'][0]['tabs']] </code></pre> <p>Or, you can iterate over its...
0
2015-09-07T00:31:56Z
[ "python", "json" ]
Emacs: Set/Reset python debug breakpoint
2,332,164
<p>I use python debugger pdb. I use emacs for python programming. I use python-mode.el. My idea is to make emacs intuitive. So I need the following help for python programs (.py)</p> <ol> <li><p>Whenever I press 'F9' key, the emacs should put "import pdb; pdb.set_trace();" statements in the current line and move the c...
4
2010-02-25T06:43:06Z
2,350,051
<p>to do 1) </p> <pre><code>(defun add-py-debug () "add debug code and move line down" (interactive) (move-beginning-of-line 1) (insert "import pdb; pdb.set_trace();\n")) (local-set-key (kbd "&lt;f9&gt;") 'add-py-debug) </code></pre> <p>to do 2) you probably have to change the syntax hig...
7
2010-02-28T04:09:14Z
[ "python", "debugging", "emacs", "elisp", "customization" ]
Emacs: Set/Reset python debug breakpoint
2,332,164
<p>I use python debugger pdb. I use emacs for python programming. I use python-mode.el. My idea is to make emacs intuitive. So I need the following help for python programs (.py)</p> <ol> <li><p>Whenever I press 'F9' key, the emacs should put "import pdb; pdb.set_trace();" statements in the current line and move the c...
4
2010-02-25T06:43:06Z
2,350,068
<p>I've found that <a href="http://xahlee.org/emacs/elisp.html" rel="nofollow">Xah's Elisp Tutorial</a> is an excellent starting point in figuring out the basics of Emacs Lisp programming. <a href="http://steve.yegge.googlepages.com/effective-emacs" rel="nofollow">There</a> <a href="http://steve-yegge.blogspot.com/2008...
0
2010-02-28T04:19:20Z
[ "python", "debugging", "emacs", "elisp", "customization" ]
Better way to represent Many to many relationship in django admin
2,332,238
<p>I have a unique problem the way it should be handled in django admin.</p> <p>I have following models structure...</p> <pre><code>class Product(models.Model): name = models.CharField(max_length = 100) base_price = models.DecimalField(max_digits = 5, decimal_places = 2) def __unicode__(self): ...
5
2010-02-25T07:00:35Z
2,332,826
<p>There is no way built-in to the django admin to do what you need.</p> <p>You could create your own custom view, and do it that way. You can add extra views to an admin.ModelAdmin class, that will do what you need.</p>
0
2010-02-25T09:14:20Z
[ "python", "django", "django-models", "django-admin" ]
Better way to represent Many to many relationship in django admin
2,332,238
<p>I have a unique problem the way it should be handled in django admin.</p> <p>I have following models structure...</p> <pre><code>class Product(models.Model): name = models.CharField(max_length = 100) base_price = models.DecimalField(max_digits = 5, decimal_places = 2) def __unicode__(self): ...
5
2010-02-25T07:00:35Z
2,333,500
<p>This is -- potentially -- a terrible design. Your database table should contain the correct price.</p> <p>Your application must now do two things. It must get a default price from somewhere else (not in this table) and it must also get an override price (from this table) and put the two pieces of information toge...
0
2010-02-25T11:13:10Z
[ "python", "django", "django-models", "django-admin" ]
Better way to represent Many to many relationship in django admin
2,332,238
<p>I have a unique problem the way it should be handled in django admin.</p> <p>I have following models structure...</p> <pre><code>class Product(models.Model): name = models.CharField(max_length = 100) base_price = models.DecimalField(max_digits = 5, decimal_places = 2) def __unicode__(self): ...
5
2010-02-25T07:00:35Z
2,339,871
<p>I got the solution, here is my answer to my question... Let me share it with you... I changed the model in following way....</p> <pre><code>class Product(models.Model): name = models.CharField(max_length = 100) base_price = models.DecimalField(max_digits = 5, decimal_places = 2) def __unicode__(sel...
1
2010-02-26T06:30:40Z
[ "python", "django", "django-models", "django-admin" ]
PyFacebook: Facebook() instance has no stream methods
2,332,315
<p>I need to update my Facebook Fan Page in a django app so I have this code:</p> <pre><code>import facebook from django.conf import settings def login_facebook(): fb = facebook.Facebook(settings.FACEBOOK_API_KEY, settings.FACEBOOK_SECRET_KEY) fb.session_key = settings.FACEBOOK_SESSION fb.secret = setting...
1
2010-02-25T07:19:37Z
2,332,437
<p>After searching for hours I finally found the solution... not to use stream methods but this:</p> <pre><code>fb(method='stream_publish', args={'session_key': settings.FACEBOOK_SESSION, 'uid':PAGE_ID, 'target_id': 'NULL', 'message':'MESSAGE_HERE'}) </code></pre> <p>Found the solution at this blog post: <a href="htt...
1
2010-02-25T07:47:27Z
[ "python", "facebook", "pyfacebook" ]
Migrate a SQLite3 database table to MySQL with Python without dump files
2,332,609
<p>I need to migrate information that I created in SQLite3 to a MySQL database on my website. The website is on a hosted server. I have remote access to the MySQL database. I initially thought it would be easy, but I am not finding any good info on it, and everything I read seems to imply that you need to dump the S...
1
2010-02-25T08:29:52Z
2,332,711
<p>The reason the "messy" scripts are required is that it's generally a difficult problem to solve.</p> <p>If you are lucky there won't be too many schema incompatibilities between the databases.</p> <p>These may help</p> <p><a href="http://www.djangosnippets.org/snippets/14/" rel="nofollow">db_dump.py</a><br> <a hr...
2
2010-02-25T08:51:07Z
[ "python", "mysql", "django", "sqlite3" ]
Migrate a SQLite3 database table to MySQL with Python without dump files
2,332,609
<p>I need to migrate information that I created in SQLite3 to a MySQL database on my website. The website is on a hosted server. I have remote access to the MySQL database. I initially thought it would be easy, but I am not finding any good info on it, and everything I read seems to imply that you need to dump the S...
1
2010-02-25T08:29:52Z
2,332,855
<p>Have you tried using django-admin's dumpdata and loaddata?</p> <p>e.g. dump sqllite3 db </p> <pre><code>manage.py dumpdata </code></pre> <p>change db to mysql, recreate tables and load</p> <pre><code>manage.py loaddata mydata.json </code></pre> <p>dumpdata by default dumps json but you can set format to xml too...
2
2010-02-25T09:20:06Z
[ "python", "mysql", "django", "sqlite3" ]
customize the django admin panel?
2,333,360
<p>I want to change the django bydefault admin panel title bar where wirte the <strong>django administration</strong>. Actually I want to replace the <strong>django administration</strong> with the my site name.</p>
5
2010-02-25T10:49:14Z
2,333,383
<p>Have a look a django-grappelli : <a href="http://code.google.com/p/django-grappelli/" rel="nofollow">http://code.google.com/p/django-grappelli/</a></p> <p>Or</p> <p>Do it yourself : <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates" rel="nofollow">http://docs.djangoproject...
1
2010-02-25T10:52:42Z
[ "python", "django", "django-admin" ]
customize the django admin panel?
2,333,360
<p>I want to change the django bydefault admin panel title bar where wirte the <strong>django administration</strong>. Actually I want to replace the <strong>django administration</strong> with the my site name.</p>
5
2010-02-25T10:49:14Z
2,342,021
<p>I found out the solution: Make the file in notpad </p> <pre><code>{% extends "admin/base.html" %} {% load i18n %} {% block title %}{{ title }} | {% trans 'Your Customize name' %}{% endblock %} {% block branding %} &lt;h1 id="site-name"&gt;{% trans 'Your Customize name administration' %}&lt;/h1&gt; {% endblock %} ...
6
2010-02-26T13:48:55Z
[ "python", "django", "django-admin" ]
How do I get my python object back from a QVariant in PyQt4?
2,333,420
<p>I am creating a subclass of <code>QAbstractItemModel</code> to be displayed in an <code>QTreeView</code>.</p> <p>My <code>index()</code> and <code>parent()</code> function creates the <code>QModelIndex</code> using the <code>QAbstractItemModel</code> inherited function <code>createIndex</code> and providing it the ...
5
2010-02-25T10:59:20Z
2,334,019
<p>Have you tried this?</p> <pre><code>my_python_object = my_qvariant.toPyObject() </code></pre> <p><a href="http://pyqt.sourceforge.net/Docs/PyQt4/qvariant.html#toPyObject" rel="nofollow">http://pyqt.sourceforge.net/Docs/PyQt4/qvariant.html#toPyObject</a> (just for completeness, but there isn't much to see there...)...
12
2010-02-25T12:46:34Z
[ "python", "pyqt4", "qvariant", "qabstractitemmodel" ]
How do I get my python object back from a QVariant in PyQt4?
2,333,420
<p>I am creating a subclass of <code>QAbstractItemModel</code> to be displayed in an <code>QTreeView</code>.</p> <p>My <code>index()</code> and <code>parent()</code> function creates the <code>QModelIndex</code> using the <code>QAbstractItemModel</code> inherited function <code>createIndex</code> and providing it the ...
5
2010-02-25T10:59:20Z
2,334,179
<p>The key thing is to use <code>internalPointer()</code> directly on the <code>QModelIndex</code>, not dealing with the <code>QVariant</code> at all.</p> <pre><code>class TestModel(QAbstractItemModel): def __init__(self, plan): QAbstractItemModel.__init__(self) def index(self, row, column, parent): ...
4
2010-02-25T13:16:23Z
[ "python", "pyqt4", "qvariant", "qabstractitemmodel" ]
Return common element indices between two numpy arrays
2,333,593
<p>I have two arrays, a1 and a2. Assume <code>len(a2) &gt;&gt; len(a1)</code>, and that a1 is a subset of a2. </p> <p>I would like a quick way to return the a2 indices of all elements in a1. The time-intensive way to do this is obviously:</p> <pre><code>from operator import indexOf indices = [] for i in a1: indic...
8
2010-02-25T11:29:34Z
2,333,646
<p>how about:</p> <pre><code>wanted = set(a1) indices =[idx for (idx, value) in enumerate(a2) if value in wanted] </code></pre> <p>This should be O(len(a1)+len(a2)) instead of O(len(a1)*len(a2))</p> <p>NB I don't know numpy so there may be a more 'numpythonic' way to do it, but this is how I would do it in pure pyth...
2
2010-02-25T11:38:03Z
[ "python", "arrays", "numpy" ]
Return common element indices between two numpy arrays
2,333,593
<p>I have two arrays, a1 and a2. Assume <code>len(a2) &gt;&gt; len(a1)</code>, and that a1 is a subset of a2. </p> <p>I would like a quick way to return the a2 indices of all elements in a1. The time-intensive way to do this is obviously:</p> <pre><code>from operator import indexOf indices = [] for i in a1: indic...
8
2010-02-25T11:29:34Z
2,333,682
<p>How about</p> <pre><code>numpy.nonzero(numpy.in1d(a2, a1))[0] </code></pre> <p>This should be fast. From my basic testing, it's about 7 times faster than your second code snippet for <code>len(a2) == 100</code>, <code>len(a1) == 10000</code>, and only one common element at index 45. This assumes that both <code>...
7
2010-02-25T11:47:30Z
[ "python", "arrays", "numpy" ]
Return common element indices between two numpy arrays
2,333,593
<p>I have two arrays, a1 and a2. Assume <code>len(a2) &gt;&gt; len(a1)</code>, and that a1 is a subset of a2. </p> <p>I would like a quick way to return the a2 indices of all elements in a1. The time-intensive way to do this is obviously:</p> <pre><code>from operator import indexOf indices = [] for i in a1: indic...
8
2010-02-25T11:29:34Z
19,606,580
<pre><code>index = in1d(a2,a1) result = a2[index] </code></pre>
1
2013-10-26T12:14:42Z
[ "python", "arrays", "numpy" ]
Return common element indices between two numpy arrays
2,333,593
<p>I have two arrays, a1 and a2. Assume <code>len(a2) &gt;&gt; len(a1)</code>, and that a1 is a subset of a2. </p> <p>I would like a quick way to return the a2 indices of all elements in a1. The time-intensive way to do this is obviously:</p> <pre><code>from operator import indexOf indices = [] for i in a1: indic...
8
2010-02-25T11:29:34Z
37,905,358
<p>The <a href="https://github.com/EelcoHoogendoorn/Numpy_arraysetops_EP" rel="nofollow">numpy_indexed</a> package (disclaimer: I am its author) contains a vectorized equivalent of list.index; performance should be similar to the currently accepted answer, but as a bonus, it gives you explicit control over missing valu...
0
2016-06-19T08:33:26Z
[ "python", "arrays", "numpy" ]
Can't modify value returned by time.time() in Python code embedded in C++
2,333,848
<p>I'm facing a very strange problem.</p> <p>The following code:</p> <pre><code>import time target_time = time.time() + 30.0 </code></pre> <p>doesn't work in Python code called from C++ (embedding)!</p> <p>target_time has the same value as time.time() and any attempt to modify it leaves the value unchanged in a pdb...
1
2010-02-25T12:16:19Z
2,342,036
<p>Found the answer in that thread: <a href="http://www.ogre3d.org/forums/viewtopic.php?f=1&amp;t=55013&amp;p=373940&amp;hilit=D3DCREATE_FPU_PRESERVE#p373940" rel="nofollow">http://www.ogre3d.org/forums/viewtopic.php?f=1&amp;t=55013&amp;p=373940&amp;hilit=D3DCREATE_FPU_PRESERVE#p373940</a></p> <p><a href="http://msdn....
0
2010-02-26T13:52:01Z
[ "c++", "python", "direct3d", "embedding", "ogre3d" ]
Python equivalents of the common Perl modules?
2,333,851
<p>I need to rewrite some Perl code in python. So I'm looking for the closest modules to what I'm using now in Perl (i.e. with similar functionality and stability):</p> <ul> <li><a href="http://search.cpan.org/perldoc/DBI">DBI</a> + <a href="http://search.cpan.org/perldoc/DBD%3a%3amysql">DBD::mysql</a></li> <li><a hre...
6
2010-02-25T12:17:01Z
2,333,883
<ul> <li>All Python database modules use the same API, so either <a href="http://sourceforge.net/projects/mysql-python/"><code>MySQLdb</code></a> or <a href="http://packages.python.org/oursql/"><code>oursql</code></a> will work.</li> <li><a href="http://docs.python.org/library/urllib2.html"><code>urllib2</code></a></li...
14
2010-02-25T12:23:44Z
[ "python", "perl", "migration" ]
Python equivalents of the common Perl modules?
2,333,851
<p>I need to rewrite some Perl code in python. So I'm looking for the closest modules to what I'm using now in Perl (i.e. with similar functionality and stability):</p> <ul> <li><a href="http://search.cpan.org/perldoc/DBI">DBI</a> + <a href="http://search.cpan.org/perldoc/DBD%3a%3amysql">DBD::mysql</a></li> <li><a hre...
6
2010-02-25T12:17:01Z
2,334,047
<h3>DBI + DBD::mysql</h3> <ul> <li><a href="http://sourceforge.net/projects/mysql-python/">MySQLdb</a></li> </ul> <h3>LWP::UserAgent</h3> <ul> <li><a href="http://docs.python.org/library/urllib.html">urllib</a> (Python STL)</li> <li><a href="http://docs.python.org/library/urllib2.html">urllib2</a> (Python STL)</li> ...
15
2010-02-25T12:52:00Z
[ "python", "perl", "migration" ]
atomic writing to file with Python
2,333,872
<p>I am using Python to write chunks of text to files in a single operation:</p> <pre><code>open(file, 'w').write(text) </code></pre> <p>If the script is interrupted so a file write does not complete I want to have no file rather than a partially complete file. Can this be done?</p>
32
2010-02-25T12:21:41Z
2,333,979
<p>Write data to a temporary file and when data has been successfully written, rename the file to the correct destination file e.g</p> <pre><code>f = open(tmpFile, 'w') f.write(text) # make sure that all data is on disk # see http://stackoverflow.com/questions/7433057/is-rename-without-fsync-safe f.flush() os.fsync(f....
65
2010-02-25T12:39:49Z
[ "python", "file-io", "atomic" ]
atomic writing to file with Python
2,333,872
<p>I am using Python to write chunks of text to files in a single operation:</p> <pre><code>open(file, 'w').write(text) </code></pre> <p>If the script is interrupted so a file write does not complete I want to have no file rather than a partially complete file. Can this be done?</p>
32
2010-02-25T12:21:41Z
11,639,200
<p>There is a simple AtomicFile helper: <a href="https://github.com/sashka/atomicfile">https://github.com/sashka/atomicfile</a></p>
5
2012-07-24T20:58:35Z
[ "python", "file-io", "atomic" ]
atomic writing to file with Python
2,333,872
<p>I am using Python to write chunks of text to files in a single operation:</p> <pre><code>open(file, 'w').write(text) </code></pre> <p>If the script is interrupted so a file write does not complete I want to have no file rather than a partially complete file. Can this be done?</p>
32
2010-02-25T12:21:41Z
25,586,245
<p>I’m using this code to atomically replace/write a file:</p> <pre><code>import os from contextlib import contextmanager @contextmanager def atomic_write(filepath, binary=False, fsync=False): """ Writeable file object that atomically updates a file (using a temporary file). :param filepath: the file path ...
3
2014-08-30T19:59:38Z
[ "python", "file-io", "atomic" ]
atomic writing to file with Python
2,333,872
<p>I am using Python to write chunks of text to files in a single operation:</p> <pre><code>open(file, 'w').write(text) </code></pre> <p>If the script is interrupted so a file write does not complete I want to have no file rather than a partially complete file. Can this be done?</p>
32
2010-02-25T12:21:41Z
29,491,523
<p>A simple snippet that implements atomic writing using Python <code>tempfile</code>.</p> <pre><code>with open_atomic('test.txt', 'w') as f: f.write("huzza") </code></pre> <p>or even reading and writing to and from the same file:</p> <pre><code>with open('test.txt', 'r') as src: with open_atomic('test.txt',...
5
2015-04-07T12:23:43Z
[ "python", "file-io", "atomic" ]
atomic writing to file with Python
2,333,872
<p>I am using Python to write chunks of text to files in a single operation:</p> <pre><code>open(file, 'w').write(text) </code></pre> <p>If the script is interrupted so a file write does not complete I want to have no file rather than a partially complete file. Can this be done?</p>
32
2010-02-25T12:21:41Z
38,075,304
<p>Since it is very easy to mess up with the details, I recommend using a tiny library for that. The advantage of a library is that it takes care all these nitty-gritty details, and is being <a href="https://github.com/untitaker/python-atomicwrites/issues?utf8=%E2%9C%93&amp;q=" rel="nofollow">reviewed and improved</a> ...
1
2016-06-28T11:43:30Z
[ "python", "file-io", "atomic" ]
A decent SSL library for Python 2.5
2,334,354
<p>I am tasked with migrating a server's networking from plain sockets to SSL in python 2.5, and I've run into a snag. It seems that just about no SSL library out there fully implements the socket interface, so the code we currently have can't be straight migrated.</p> <p>Specifically, I can't seem to find a library t...
1
2010-02-25T13:47:55Z
2,334,382
<p><a href="http://pyopenssl.sourceforge.net/" rel="nofollow">pyOpenSSL</a> seems to support <code>setblocking()</code>.</p>
0
2010-02-25T13:52:03Z
[ "python", "ssl" ]
A decent SSL library for Python 2.5
2,334,354
<p>I am tasked with migrating a server's networking from plain sockets to SSL in python 2.5, and I've run into a snag. It seems that just about no SSL library out there fully implements the socket interface, so the code we currently have can't be straight migrated.</p> <p>Specifically, I can't seem to find a library t...
1
2010-02-25T13:47:55Z
2,335,122
<p>How about <a href="http://pypi.python.org/pypi/ssl" rel="nofollow">this backport of Python 2.6's <code>ssl</code> module to Python 2.3+</a>? It provides the same functionality <a href="http://docs.python.org/dev/library/ssl.html" rel="nofollow">described here</a>, which appears to mean that it takes a normal <code>...
2
2010-02-25T15:23:04Z
[ "python", "ssl" ]
Customizing the language-guessing algorithm in Django
2,334,402
<p>I'm developing a multilingual Django website. It has two languages, English and Hebrew. I want the default language for every first-time visitor to be Hebrew, regardless of what his browser's <code>Accept-Language</code> is.</p> <p>Of course, if he changes language to English (and thus gets the language cookie or t...
0
2010-02-25T13:54:51Z
2,334,440
<p>Start by reading this: <a href="http://docs.djangoproject.com/en/1.1/topics/i18n/#topics-i18n" rel="nofollow">http://docs.djangoproject.com/en/1.1/topics/i18n/#topics-i18n</a></p> <p>Then read this: <a href="http://docs.djangoproject.com/en/1.1/topics/i18n/internationalization/#topics-i18n-internationalization" rel...
0
2010-02-25T14:02:01Z
[ "python", "django", "django-multilingual" ]
Customizing the language-guessing algorithm in Django
2,334,402
<p>I'm developing a multilingual Django website. It has two languages, English and Hebrew. I want the default language for every first-time visitor to be Hebrew, regardless of what his browser's <code>Accept-Language</code> is.</p> <p>Of course, if he changes language to English (and thus gets the language cookie or t...
0
2010-02-25T13:54:51Z
2,336,824
<p>Maybe you don't have to override anything. You can just check on the first page, (or maybe every page) if the user already has a language cookie and otherwise redirect him to the set_language redirect view. In that way you could force the language to Hebrew. </p> <p>If the user decides to change back to English, he...
0
2010-02-25T19:10:56Z
[ "python", "django", "django-multilingual" ]
How to parse a single line csv string without the csv.reader iterator in python?
2,334,436
<p>I have a CSV file that i need to rearrange and renecode. I'd like to run</p> <pre><code>line = line.decode('windows-1250').encode('utf-8') </code></pre> <p>on each line before it's parsed and split by the CSV reader. Or I'd like iterate over lines myself run the re-encoding and use just single line parsing form CS...
0
2010-02-25T14:01:05Z
2,334,457
<p>Loop over lines on file can be done this way:</p> <pre><code>with open('path/to/my/file.csv', 'r') as f: for line in f: puts line # here You can convert encoding and save lines </code></pre> <p>But if You want to convert encoding of a whole file You can also call:</p> <pre><code>$ iconv -f Windows-125...
2
2010-02-25T14:05:11Z
[ "python", "csv" ]
How to parse a single line csv string without the csv.reader iterator in python?
2,334,436
<p>I have a CSV file that i need to rearrange and renecode. I'd like to run</p> <pre><code>line = line.decode('windows-1250').encode('utf-8') </code></pre> <p>on each line before it's parsed and split by the CSV reader. Or I'd like iterate over lines myself run the re-encoding and use just single line parsing form CS...
0
2010-02-25T14:01:05Z
2,334,722
<p>Thx, for the answers. The wrapping one gave me an idea:</p> <pre><code>def reencode(file): for line in file: yield line.decode('windows-1250').encode('utf-8') csv_writer = csv.writer(open(outfilepath,'w'), delimiter=',',quotechar='"', quoting=csv.QUOTE_MINIMAL) csv_reader = csv.reader(reencode(open(fil...
2
2010-02-25T14:38:00Z
[ "python", "csv" ]
How to parse a single line csv string without the csv.reader iterator in python?
2,334,436
<p>I have a CSV file that i need to rearrange and renecode. I'd like to run</p> <pre><code>line = line.decode('windows-1250').encode('utf-8') </code></pre> <p>on each line before it's parsed and split by the CSV reader. Or I'd like iterate over lines myself run the re-encoding and use just single line parsing form CS...
0
2010-02-25T14:01:05Z
2,336,832
<p>At the very bottom of the <a href="http://docs.python.org/library/csv.html" rel="nofollow">csv documentation</a> is a set of classes (UnicodeReader and UnicodeWriter) that implements Unicode support for csv:</p> <pre><code>rfile = open('input.csv') wfile = open('output.csv','w') csv_reader = UnicodeReader(rfile,enc...
2
2010-02-25T19:12:07Z
[ "python", "csv" ]
Error loading dll in path with parenthesis using ctypes (python)
2,334,627
<p>I am trying to access a dll located in the "c:/Program Files (x86)" folder in a 64-bits processor PC.</p> <p>If I use os.path.exists to check if the dll exists, I receive an afirmative answer:</p> <pre><code>&gt;&gt;&gt; print os.path.exists('c:/Program Files (x86)/Some Folder/SomeDll.dll') True </code></pre> <p>...
5
2010-02-25T14:26:54Z
2,334,857
<p>Have you tried "C:/Progra~1/SomeFolder/SomeDll" ?</p> <p>Another suggestion: </p> <pre><code> os.chdir(r"C:\Program Files(x86)\SomeFolder") the_dll = WinDLL("SomeDLL.dll") </code></pre>
6
2010-02-25T14:52:52Z
[ "python", "dll", "ctypes" ]
Hexagonal Self-Organizing map in Python
2,334,629
<p>I am looking for <strong>hexagonal</strong> <a href="http://en.wikipedia.org/wiki/Self-organizing_map">self-organizing map</a> on Python.<br></p> <p><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Tiling_Regular_6-3_Hexagonal.svg/200px-Tiling_Regular_6-3_Hexagonal.svg.png" alt="hexagonal tiling">...
7
2010-02-25T14:27:14Z
2,340,216
<p>I don't have an answer for point 1, but some hints for point 2 and 3. In your context, you're not modelling a physical 2D space but a conceptual space with tiles that have 6 neighbors. This can be modelled with square tiles arranged in columns with the odd colums shifted vertically by half the size of a square. I'll...
6
2010-02-26T08:03:29Z
[ "python", "module", "artificial-intelligence", "neural-network", "self-organizing-maps" ]
Hexagonal Self-Organizing map in Python
2,334,629
<p>I am looking for <strong>hexagonal</strong> <a href="http://en.wikipedia.org/wiki/Self-organizing_map">self-organizing map</a> on Python.<br></p> <p><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Tiling_Regular_6-3_Hexagonal.svg/200px-Tiling_Regular_6-3_Hexagonal.svg.png" alt="hexagonal tiling">...
7
2010-02-25T14:27:14Z
23,689,112
<p>I know this discussion is 4 years old, however I haven't find a satisfactory answer over the web.</p> <p>If you have something as a array mapping the input to the neuron and a 2-d array related to the location for each neuron.</p> <p>For this example imagine something like:</p> <pre><code>hits = array([1, 24, 14,...
3
2014-05-15T21:35:37Z
[ "python", "module", "artificial-intelligence", "neural-network", "self-organizing-maps" ]
Django queries: how to make contains OR not_contains queries
2,334,698
<p>I have to make a query that will get records containing "wd2" substring or not containing "wd" string at all. Is there any way to do it nicely?</p> <p>Seems something like:</p> <p><code>Record.objects.filter( Q(parameter__icontains="wd2") | Q( ## what should be here? ## ) )</code></p>
6
2010-02-25T14:35:41Z
2,334,784
<p>From the django <a href="http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects">q object documentation</a>:</p> <blockquote> <p>You can compose statements of arbitrary complexity by combining Q objects with the &amp; and | operators and use parenthetical grouping. Also, Q objects ...
12
2010-02-25T14:43:52Z
[ "python", "django" ]
Can distutils use a custom .def to expose extra symbols when it compiles a Windows .dll?
2,334,754
<p>I'm abusing distutils to compile an extension module for Python, but rather than using the Python C API I'm using ctypes to talk to the resulting shared library.</p> <p>This works fine in Linux because it automatically exports all symbols in a shared library, but in Windows distutils provides a <code>.def</code> to...
0
2010-02-25T14:41:18Z
2,334,890
<p>You can pass ['-Wl,--export-all-symbols'] as extra_link_args if you're using Mingw's GCC. There's probably a similar setting for Visual, somewhere in the IDE.</p> <p>This works only if distutils chooses to use "gcc -mdll" as a linker instead of "dllwrap". It does so if your ld version is later than 2.10.90, which s...
1
2010-02-25T14:56:25Z
[ "python", "windows", "dll", "distutils", "dllexport" ]
XML differences between WCF and Python SUDS for inheritance?
2,334,874
<p>This is my first post, so apologies if I don't include all the right information!</p> <p>I have a question regarding the different ways inheritance are represented between WCF and SUDS (Python). I have a C++/CLI WCF server (.NET 3.5 SP1) and I'm trying to communicate with it. I've used a C# (WCF also) client and ...
15
2010-02-25T14:54:17Z
6,003,458
<p>You could use the data contract serializer to control how the xml is created and read. See: <a href="http://msdn.microsoft.com/en-us/library/ms731073.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms731073.aspx</a></p>
0
2011-05-14T17:11:17Z
[ "python", "wcf", "inheritance", "soap", "suds" ]
XML differences between WCF and Python SUDS for inheritance?
2,334,874
<p>This is my first post, so apologies if I don't include all the right information!</p> <p>I have a question regarding the different ways inheritance are represented between WCF and SUDS (Python). I have a C++/CLI WCF server (.NET 3.5 SP1) and I'm trying to communicate with it. I've used a C# (WCF also) client and ...
15
2010-02-25T14:54:17Z
6,864,392
<p>Don't know about the python side but there are couple of options on the WCF side. The more straight foward option is to create a <a href="http://msdn.microsoft.com/en-us/library/aa717047.aspx" rel="nofollow">message inspector</a> to detect and convert the python generated soap to something more palatable to the WCF ...
1
2011-07-28T19:13:24Z
[ "python", "wcf", "inheritance", "soap", "suds" ]
PyQt4: Adding QtMessageBox.information functionality to custom window
2,335,104
<p>what I need is something very alike QtMessageBox.information method, but I need it form my custom window.</p> <p>I need a one window with few labels, one QtTreeViewWidget, one QButtonGroup … This window will be called from main window. If we call class that implements called window as SelectionWindow, than what I...
0
2010-02-25T15:21:17Z
2,362,675
<p>I would do something like this:</p> <ul> <li>dialog window with buttonbox -> events connected to accept() and reject() slots of the dialog itself</li> <li>set the dialog modality to something like application modal</li> <li>call the exec_() method of the dialog to keep it blocking until the user chooses ok/cancel</...
0
2010-03-02T11:16:48Z
[ "python", "pyqt4" ]
What is the scope of a defaulted parameter in Python?
2,335,160
<p>When you define a function in Python with an array parameter, what is the scope of that parameter?</p> <p>This example is taken from the Python tutorial:</p> <pre><code>def f(a, L=[]): L.append(a) return L print f(1) print f(2) print f(3) </code></pre> <p>Prints:</p> <pre><code>[1] [1, 2] [1, 2, 3] </co...
11
2010-02-25T15:26:36Z
2,335,174
<p>The scope is as you would expect.</p> <p>The perhaps surprising thing is that the default value is only calculated once and reused, so each time you call the function you get the same list, not a new list initialized to [].</p> <p>The list is stored in <code>f.func_defaults</code>.</p> <pre><code>def f(a, L=[]): ...
12
2010-02-25T15:28:08Z
[ "python", "scope", "parameters", "default-value", "function-calls" ]
What is the scope of a defaulted parameter in Python?
2,335,160
<p>When you define a function in Python with an array parameter, what is the scope of that parameter?</p> <p>This example is taken from the Python tutorial:</p> <pre><code>def f(a, L=[]): L.append(a) return L print f(1) print f(2) print f(3) </code></pre> <p>Prints:</p> <pre><code>[1] [1, 2] [1, 2, 3] </co...
11
2010-02-25T15:26:36Z
2,335,187
<p>The scope of the <code>L</code> variable is behaving as you expect. </p> <p>The "problem" is with the list you're creating with <code>[]</code>. Python does not create a new list each time you call the function. <code>L</code> gets assigned the same list each time you call which is why the function "remembers" p...
3
2010-02-25T15:29:24Z
[ "python", "scope", "parameters", "default-value", "function-calls" ]
What is the scope of a defaulted parameter in Python?
2,335,160
<p>When you define a function in Python with an array parameter, what is the scope of that parameter?</p> <p>This example is taken from the Python tutorial:</p> <pre><code>def f(a, L=[]): L.append(a) return L print f(1) print f(2) print f(3) </code></pre> <p>Prints:</p> <pre><code>[1] [1, 2] [1, 2, 3] </co...
11
2010-02-25T15:26:36Z
2,335,197
<p>There's even less "magic" than you might suspect. This is equivalent to </p> <pre><code>m = [] def f(a, L=m): L.append(a) return L print f(1) print f(2) print f(3) </code></pre> <p><code>m</code> is only created once.</p>
3
2010-02-25T15:30:47Z
[ "python", "scope", "parameters", "default-value", "function-calls" ]
What is the scope of a defaulted parameter in Python?
2,335,160
<p>When you define a function in Python with an array parameter, what is the scope of that parameter?</p> <p>This example is taken from the Python tutorial:</p> <pre><code>def f(a, L=[]): L.append(a) return L print f(1) print f(2) print f(3) </code></pre> <p>Prints:</p> <pre><code>[1] [1, 2] [1, 2, 3] </co...
11
2010-02-25T15:26:36Z
2,335,258
<p>The "problem" here is that <code>L=[]</code> is only evaluated <em>once</em>, that is, when the file is compiled. Python steps through each line of the file and compiles it. By the time it reaches the <code>def</code> with the default parameter, it creates that list instance once.</p> <p>If you put <code>L = []</co...
0
2010-02-25T15:39:53Z
[ "python", "scope", "parameters", "default-value", "function-calls" ]
What is the scope of a defaulted parameter in Python?
2,335,160
<p>When you define a function in Python with an array parameter, what is the scope of that parameter?</p> <p>This example is taken from the Python tutorial:</p> <pre><code>def f(a, L=[]): L.append(a) return L print f(1) print f(2) print f(3) </code></pre> <p>Prints:</p> <pre><code>[1] [1, 2] [1, 2, 3] </co...
11
2010-02-25T15:26:36Z
2,335,263
<p>The explaination is given in answers to <a href="http://stackoverflow.com/questions/1132941/least-astonishment-in-python-the-mutable-default-argument">this question</a>. To sum it up here:</p> <p>Functions in Python are a kind of object. Because they are a kind of object, they act like objects when instantiated. A...
0
2010-02-25T15:40:16Z
[ "python", "scope", "parameters", "default-value", "function-calls" ]
What is the scope of a defaulted parameter in Python?
2,335,160
<p>When you define a function in Python with an array parameter, what is the scope of that parameter?</p> <p>This example is taken from the Python tutorial:</p> <pre><code>def f(a, L=[]): L.append(a) return L print f(1) print f(2) print f(3) </code></pre> <p>Prints:</p> <pre><code>[1] [1, 2] [1, 2, 3] </co...
11
2010-02-25T15:26:36Z
2,335,353
<p>You have to keep in mind that python is an interpreted language. What is happening here is when the function "f" is defined, it creates the list and assigns it to the default parameter "L" of function "f". Later, when you call this function, the same list is used as the default parameter. In short, the code on th...
-1
2010-02-25T15:52:50Z
[ "python", "scope", "parameters", "default-value", "function-calls" ]
What is the scope of a defaulted parameter in Python?
2,335,160
<p>When you define a function in Python with an array parameter, what is the scope of that parameter?</p> <p>This example is taken from the Python tutorial:</p> <pre><code>def f(a, L=[]): L.append(a) return L print f(1) print f(2) print f(3) </code></pre> <p>Prints:</p> <pre><code>[1] [1, 2] [1, 2, 3] </co...
11
2010-02-25T15:26:36Z
2,335,665
<p>Say you have the following code:</p> <pre><code>def func(a=[]): a.append(1) print("A:", a) func() func() func() </code></pre> <p>You can use python's indentation to help you understand what's going on. Everything that is flush to the left margin is executed when the file gets executed. Everything that's...
0
2010-02-25T16:31:39Z
[ "python", "scope", "parameters", "default-value", "function-calls" ]
model.__unicode__() returning russian string cause TemplateSyntaxError
2,335,213
<p>code:</p> <pre><code>class Gallery(models.Model): title = models.CharField(max_length=100) description = models.TextField(blank=True) created = models.DateField(auto_now_add=True) class Meta: verbose_name = 'галерея' verbose_name_plural = 'галереи' def __unicode...
0
2010-02-25T15:33:23Z
2,335,248
<p>Try</p> <pre><code>return u'Галерея %s' % self.title </code></pre>
1
2010-02-25T15:38:03Z
[ "python", "django", "unicode", "ascii" ]
model.__unicode__() returning russian string cause TemplateSyntaxError
2,335,213
<p>code:</p> <pre><code>class Gallery(models.Model): title = models.CharField(max_length=100) description = models.TextField(blank=True) created = models.DateField(auto_now_add=True) class Meta: verbose_name = 'галерея' verbose_name_plural = 'галереи' def __unicode...
0
2010-02-25T15:33:23Z
2,336,420
<p>Because self.title is a unicode string and your string literal is not (its type is str), when Python executes the expression <code>'Галерея %s' % self.title</code>, it needs to coerce the string literal into unicode before performing the interpolation. It needs a character encoding to do this, and by default ...
0
2010-02-25T18:05:55Z
[ "python", "django", "unicode", "ascii" ]
model.__unicode__() returning russian string cause TemplateSyntaxError
2,335,213
<p>code:</p> <pre><code>class Gallery(models.Model): title = models.CharField(max_length=100) description = models.TextField(blank=True) created = models.DateField(auto_now_add=True) class Meta: verbose_name = 'галерея' verbose_name_plural = 'галереи' def __unicode...
0
2010-02-25T15:33:23Z
5,123,133
<p>to avoid errors like this, put it at the beginning of your file</p> <pre><code># -*- coding: utf-8 -*- </code></pre>
0
2011-02-25T21:52:35Z
[ "python", "django", "unicode", "ascii" ]
Post processing attendance data with Django
2,335,239
<p>I have a web app which tries to determine when people are attending events.</p> <pre><code>class Attendee(models.Model): location = models.ForeignKey(Location) user = models.ForeignKey(User) checked_in = models.DateTimeField() checked_out = models.DateTimeField() last_active = models.DateTimeFie...
0
2010-02-25T15:36:55Z
2,335,424
<p>You don't need a 'Django equivalent to a cron job', you just need a cron job. </p> <p>The cron should run a standalone Django script - you can do this in several different ways, but the easiest way is to create a <a href="http://docs.djangoproject.com/en/1.1/howto/custom-management-commands/" rel="nofollow">standal...
1
2010-02-25T16:01:42Z
[ "python", "django" ]
Send Email in Django without SMTP server. Like php mail() function does
2,335,384
<p>As far as I read, Django only supports sending mails using SMTP.</p> <p>I would like to send Emails from my script in Django, but do not want to setup SMTP server (it's too complex for me, I'm a linux newbie).</p> <p>Is it possible, to send mails in Django in the same way like I do it in PHP, without providing SMT...
6
2010-02-25T15:56:58Z
2,335,399
<p>So how does PHP do it? By magic?</p> <p>If you don't have an SMTP server, sign up for a GMail account and use that.</p>
2
2010-02-25T15:59:02Z
[ "python", "django", "email" ]
Send Email in Django without SMTP server. Like php mail() function does
2,335,384
<p>As far as I read, Django only supports sending mails using SMTP.</p> <p>I would like to send Emails from my script in Django, but do not want to setup SMTP server (it's too complex for me, I'm a linux newbie).</p> <p>Is it possible, to send mails in Django in the same way like I do it in PHP, without providing SMT...
6
2010-02-25T15:56:58Z
2,335,741
<p>PHP uses sendmail on UNIX system to send emails. I guess at some point when you set up the system, this is, sendmail is configured.</p> <p>There is an <a href="http://pypi.python.org/pypi/sendmail/">API to sendmail</a> for Python, maybe it helps you. But there is a SMTP server involved in any case ;)</p>
5
2010-02-25T16:40:37Z
[ "python", "django", "email" ]
Send Email in Django without SMTP server. Like php mail() function does
2,335,384
<p>As far as I read, Django only supports sending mails using SMTP.</p> <p>I would like to send Emails from my script in Django, but do not want to setup SMTP server (it's too complex for me, I'm a linux newbie).</p> <p>Is it possible, to send mails in Django in the same way like I do it in PHP, without providing SMT...
6
2010-02-25T15:56:58Z
2,336,143
<p>Your hosting provider might have set up the host and any possible login credentials for all the PHP pages on their machines. This would make it seem like none are required. Your hosting provider should be more than happy to give you the information. Try searching for SMTP in their FAQ, forum, and any welcome emai...
2
2010-02-25T17:30:13Z
[ "python", "django", "email" ]
Send Email in Django without SMTP server. Like php mail() function does
2,335,384
<p>As far as I read, Django only supports sending mails using SMTP.</p> <p>I would like to send Emails from my script in Django, but do not want to setup SMTP server (it's too complex for me, I'm a linux newbie).</p> <p>Is it possible, to send mails in Django in the same way like I do it in PHP, without providing SMT...
6
2010-02-25T15:56:58Z
2,337,723
<p>Postfix and Exim were built to deal with all of the problems associated with forwarding email from your host to the rest of the world. Your app speaks SMTP to them, and they turn around and speak SMTP with the destination. But they're <strong>very, very good at it</strong>.</p> <p>There is <a href="http://lamsonp...
3
2010-02-25T21:24:25Z
[ "python", "django", "email" ]
Send Email in Django without SMTP server. Like php mail() function does
2,335,384
<p>As far as I read, Django only supports sending mails using SMTP.</p> <p>I would like to send Emails from my script in Django, but do not want to setup SMTP server (it's too complex for me, I'm a linux newbie).</p> <p>Is it possible, to send mails in Django in the same way like I do it in PHP, without providing SMT...
6
2010-02-25T15:56:58Z
4,291,867
<p>I suppose since you're using Django you're fine with Python in general. There's a new Python MTA evolving which looks very promising <a href="http://lamsonproject.org/docs/hooking_into_django.html" rel="nofollow">http://lamsonproject.org/docs/hooking_into_django.html</a></p>
0
2010-11-27T13:30:49Z
[ "python", "django", "email" ]
Python and NGREP
2,335,477
<p>I want to be able to start and stop an NGREP process from inside my python code. I really dont have experience with python on a system level.</p> <p>Normally I run NGREP from the command line, but I would like to be able to run it from a script every hour and capture the trace and then process the results.</p> <p>...
0
2010-02-25T16:06:36Z
2,335,563
<p>Look up <a href="http://docs.python.org/library/threading.html" rel="nofollow">threading.Timer</a> and <a href="http://www.noah.org/wiki/Pexpect" rel="nofollow">pexpect</a>. If you don't want to install pexpect, you can use <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">subprocess.Popen</a> ...
0
2010-02-25T16:17:09Z
[ "python", "process", "input", "system", "ngrep" ]
Python and NGREP
2,335,477
<p>I want to be able to start and stop an NGREP process from inside my python code. I really dont have experience with python on a system level.</p> <p>Normally I run NGREP from the command line, but I would like to be able to run it from a script every hour and capture the trace and then process the results.</p> <p>...
0
2010-02-25T16:06:36Z
2,335,792
<p>its not in-built, but you can try <a href="http://pycap.sourceforge.net/" rel="nofollow">Packet Capture and Injection Library</a></p>
0
2010-02-25T16:45:23Z
[ "python", "process", "input", "system", "ngrep" ]
Python and NGREP
2,335,477
<p>I want to be able to start and stop an NGREP process from inside my python code. I really dont have experience with python on a system level.</p> <p>Normally I run NGREP from the command line, but I would like to be able to run it from a script every hour and capture the trace and then process the results.</p> <p>...
0
2010-02-25T16:06:36Z
13,117,935
<p>I am not an expert but I would do this:</p> <pre><code>import subprocess import sys import re import time keep_running = 1 #Loop flag wait_hours = 12 #Stop for 12 hours and then run again run_hours = 1 #We will run ngrep for an hour. The nth run will be dumped to net_log_n.txt f_num=0 hours_so_far=0 run_time_l...
1
2012-10-29T08:11:10Z
[ "python", "process", "input", "system", "ngrep" ]
Can I use wxPython wx.ItemContainer in a derived class?
2,335,585
<p>I'm trying to make a new wx.Choice-like control (actually a replacement for wx.Choice) which uses the wx.ItemContainer to manage the list of items. Here is a minimal example showing the error:</p> <pre><code>import wx class c(wx.ItemContainer): def __init__(my): pass x = c() x.Clear() </code></pre> <p>This fa...
0
2010-02-25T16:20:09Z
2,351,160
<p>Your suspicions are on the right track. You can't subclass any of the wxWidgets types, because they're in the C++ domain and only nominally wrapped in Python. Instead, you need a Py* class, which you can subclass. The explanation is given in <a href="http://wiki.wxpython.org/CreatingCustomControls" rel="nofollow">th...
0
2010-02-28T13:23:08Z
[ "python", "wxpython" ]
Can I use wxPython wx.ItemContainer in a derived class?
2,335,585
<p>I'm trying to make a new wx.Choice-like control (actually a replacement for wx.Choice) which uses the wx.ItemContainer to manage the list of items. Here is a minimal example showing the error:</p> <pre><code>import wx class c(wx.ItemContainer): def __init__(my): pass x = c() x.Clear() </code></pre> <p>This fa...
0
2010-02-25T16:20:09Z
2,351,442
<p>wx.ItemContainer can't be instantiated directly e.g. try</p> <pre><code>x = wx.ItemContainer() </code></pre> <p>it throws error</p> <pre><code>Traceback (most recent call last): File "C:\&lt;string&gt;", line 1, in &lt;module&gt; File "D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 11812,...
1
2010-02-28T15:09:08Z
[ "python", "wxpython" ]
How can I get the window focused on Windows and re-size it?
2,335,721
<p>I want to get the focused window so I can resize it... how can I do it?</p>
6
2010-02-25T16:38:06Z
2,335,734
<p>Use the <a href="http://msdn.microsoft.com/en-us/library/ms633505%28VS.85%29.aspx">GetForegroundWindow</a> Win32 API to get the window handle.</p> <p>Then use the <a href="http://msdn.microsoft.com/en-us/library/ms633534%28VS.85%29.aspx">MoveWindow</a> (or <a href="http://msdn.microsoft.com/en-us/library/ms633545%2...
7
2010-02-25T16:39:47Z
[ "python", "windows" ]
Is fortran-like print in python possible?
2,335,856
<p>is it possible some way to "print" in python in a fortran like way like this?</p> <pre><code>1 4.5656 2 24.0900 3 698.2300 4 -3.5000 </code></pre> <p>So the decimal points is always in the same column, and we get always 3 or n decimal numbers?</p> <p>Thanks</p>
5
2010-02-25T16:53:17Z
2,335,878
<pre><code>&gt;&gt;&gt; '%11.4f' % -3.5 ' -3.5000' </code></pre> <p>or the new style formatting:</p> <pre><code>&gt;&gt;&gt; '{:11.4f}'.format(-3.5) ' -3.5000' </code></pre> <p>more about <a href="http://docs.python.org/library/string.html#formatspec">format specifiers in the docs</a>.</p>
9
2010-02-25T16:55:53Z
[ "python", "fortran" ]
Is fortran-like print in python possible?
2,335,856
<p>is it possible some way to "print" in python in a fortran like way like this?</p> <pre><code>1 4.5656 2 24.0900 3 698.2300 4 -3.5000 </code></pre> <p>So the decimal points is always in the same column, and we get always 3 or n decimal numbers?</p> <p>Thanks</p>
5
2010-02-25T16:53:17Z
2,335,880
<pre><code>for i in [(3, 4.534), (3, 15.234325), (10,341.11)]: ... print "%5i %8.4f" % i ... 3 4.5340 3 15.2343 10 341.1100 </code></pre>
0
2010-02-25T16:56:04Z
[ "python", "fortran" ]
Is fortran-like print in python possible?
2,335,856
<p>is it possible some way to "print" in python in a fortran like way like this?</p> <pre><code>1 4.5656 2 24.0900 3 698.2300 4 -3.5000 </code></pre> <p>So the decimal points is always in the same column, and we get always 3 or n decimal numbers?</p> <p>Thanks</p>
5
2010-02-25T16:53:17Z
2,335,909
<pre><code>print "%10.3f" % f </code></pre> <p>will right align the number <code>f</code> (as an aside: <code>%-10.3f</code> would be left-aligned). The string will be right-aligned to 10 characters (it doesn't work any more with > 10 characters) and exactly 3 decimal digits. So:</p> <pre><code>f = 698.230 # &lt;-- 7...
0
2010-02-25T16:59:52Z
[ "python", "fortran" ]
Is fortran-like print in python possible?
2,335,856
<p>is it possible some way to "print" in python in a fortran like way like this?</p> <pre><code>1 4.5656 2 24.0900 3 698.2300 4 -3.5000 </code></pre> <p>So the decimal points is always in the same column, and we get always 3 or n decimal numbers?</p> <p>Thanks</p>
5
2010-02-25T16:53:17Z
2,335,912
<p>You can use string.rjust(), this way:</p> <pre><code>a = 4.5656 b = 24.0900 c = 698.2300 d = -3.5000 a = "%.4f" % a b = "%.4f" % b c = "%.4f" % c d = "%.4f" % d l = max(len(a), len(b), len(c), len(d)) for i in [a, b, c, d]: print i.rjust(l+2) </code></pre> <p>Which gives:</p> <pre><code>~ $ python test...
0
2010-02-25T17:00:19Z
[ "python", "fortran" ]
Is fortran-like print in python possible?
2,335,856
<p>is it possible some way to "print" in python in a fortran like way like this?</p> <pre><code>1 4.5656 2 24.0900 3 698.2300 4 -3.5000 </code></pre> <p>So the decimal points is always in the same column, and we get always 3 or n decimal numbers?</p> <p>Thanks</p>
5
2010-02-25T16:53:17Z
6,525,562
<p>You could also take a look at the <code>fortranformat</code> library on PyPI or the <a href="https://bitbucket.org/brendanarnold/py-fortranformat/">project page</a> if you wanted to fully recreate FORTRAN text IO.</p> <p>If you have any questions, send me an email (I wrote it).</p>
5
2011-06-29T18:37:37Z
[ "python", "fortran" ]
Is fortran-like print in python possible?
2,335,856
<p>is it possible some way to "print" in python in a fortran like way like this?</p> <pre><code>1 4.5656 2 24.0900 3 698.2300 4 -3.5000 </code></pre> <p>So the decimal points is always in the same column, and we get always 3 or n decimal numbers?</p> <p>Thanks</p>
5
2010-02-25T16:53:17Z
23,597,505
<p>Fortran io is totally different to C style io in every way.</p> <p>Go for Brendan's fortranformat package.</p> <p><a href="https://pypi.python.org/pypi/fortranformat" rel="nofollow">https://pypi.python.org/pypi/fortranformat</a></p> <pre><code>easy_install fortranformat </code></pre> <p>This allows arcane old fo...
0
2014-05-11T20:24:26Z
[ "python", "fortran" ]
Is there a Python equivalent for the Perl module Term::VT102?
2,335,882
<p>In Perl there is a very handy module, Term::VT102, which allows you to create a screen in memory. This is very handy for scraping purposes since you can keep track of all the changes to portions of the screen and then export the screen as plain-text for processing. Is there an equivalent module in Python?</p> <p>Fo...
8
2010-02-25T16:56:15Z
2,336,226
<p><a href="http://www.noah.org/wiki/Pexpect" rel="nofollow">Pexpect</a>, which has support for VT100, might be of help to you.</p>
2
2010-02-25T17:39:36Z
[ "python", "perl", "screen-scraping", "command-line-interface", "vt100" ]
Is there a Python equivalent for the Perl module Term::VT102?
2,335,882
<p>In Perl there is a very handy module, Term::VT102, which allows you to create a screen in memory. This is very handy for scraping purposes since you can keep track of all the changes to portions of the screen and then export the screen as plain-text for processing. Is there an equivalent module in Python?</p> <p>Fo...
8
2010-02-25T16:56:15Z
7,240,868
<p>See also <a href="https://github.com/JulienPalard/ashttp" rel="nofollow">ashttp</a> built on top of Pexcept:</p> <blockquote> <pre><code>ashttp can serve any text application over http, like : $ ashttp 8080 top to serve a top on port 8080, or : $ ashttp 8080 watch -n 1 ls -lah /tmp to serve an actualized director...
3
2011-08-30T09:02:33Z
[ "python", "perl", "screen-scraping", "command-line-interface", "vt100" ]
How do I make a command line program that takes arguments?
2,335,989
<p>How can I make a command line, so I can execute my program on Windows with some parameters...</p> <p>For example:</p> <pre><code>C:/Program/App.exe -safemode </code></pre>
1
2010-02-25T17:11:28Z
2,336,018
<p>Not a python guy (yet anyway) but my Google-fu found this assuming you meant "handling command line arguments":<br> <a href="http://www.faqs.org/docs/diveintopython/kgp_commandline.html" rel="nofollow">http://www.faqs.org/docs/diveintopython/kgp_commandline.html</a></p>
2
2010-02-25T17:15:44Z
[ "python", "windows", "command-line" ]
How do I make a command line program that takes arguments?
2,335,989
<p>How can I make a command line, so I can execute my program on Windows with some parameters...</p> <p>For example:</p> <pre><code>C:/Program/App.exe -safemode </code></pre>
1
2010-02-25T17:11:28Z
2,336,021
<p>have a look at the <a href="http://docs.python.org/library/getopt.html" rel="nofollow"><code>getopt</code></a> and <a href="http://docs.python.org/library/optparse.html" rel="nofollow"><code>optparse</code></a> modules from the standard lib, many good things could be also said about more advanced <a href="http://cod...
9
2010-02-25T17:16:09Z
[ "python", "windows", "command-line" ]
How do I make a command line program that takes arguments?
2,335,989
<p>How can I make a command line, so I can execute my program on Windows with some parameters...</p> <p>For example:</p> <pre><code>C:/Program/App.exe -safemode </code></pre>
1
2010-02-25T17:11:28Z
2,336,023
<p>Are you speaking about parameter passed to a python script?</p> <p>'couse you can access them by</p> <pre><code>import sys print sys.argv </code></pre> <p>Or can use a more sophisticated <a href="http://www.python.org/doc/2.5.2/lib/module-getopt.html" rel="nofollow">getopt</a> module.</p>
3
2010-02-25T17:16:13Z
[ "python", "windows", "command-line" ]
How do I make a command line program that takes arguments?
2,335,989
<p>How can I make a command line, so I can execute my program on Windows with some parameters...</p> <p>For example:</p> <pre><code>C:/Program/App.exe -safemode </code></pre>
1
2010-02-25T17:11:28Z
2,336,045
<p>Or are you just asking how to open a command line?</p> <p>go to the start menu, click "run" (or just type, in Windows 7), type "cmd"</p> <p>This will open up a command shell. Given that your question is tagged python, I'm not sure it's going to be compiled into an exe, you might have to type "python (your source h...
0
2010-02-25T17:18:26Z
[ "python", "windows", "command-line" ]
How do I make a command line program that takes arguments?
2,335,989
<p>How can I make a command line, so I can execute my program on Windows with some parameters...</p> <p>For example:</p> <pre><code>C:/Program/App.exe -safemode </code></pre>
1
2010-02-25T17:11:28Z
2,336,085
<p>The other comments addressed how to handle parameters. If you want to make your python program an exe you might want to look at <a href="http://www.py2exe.org/" rel="nofollow">py2exe</a>. </p> <p>This is not required but you mentioned App.exe and not App.py</p>
0
2010-02-25T17:23:28Z
[ "python", "windows", "command-line" ]
How do I make a command line program that takes arguments?
2,335,989
<p>How can I make a command line, so I can execute my program on Windows with some parameters...</p> <p>For example:</p> <pre><code>C:/Program/App.exe -safemode </code></pre>
1
2010-02-25T17:11:28Z
2,336,101
<p>Use <a href="http://docs.python.org/library/optparse.html" rel="nofollow">optparse.OptionParser</a>.</p> <pre><code>from optparse import OptionParser import sys def make_cli_parser(): """Makes the parser for the command line interface.""" usage = "python %prog [OPTIONS]" cli_parser = OptionParser(usage...
2
2010-02-25T17:25:39Z
[ "python", "windows", "command-line" ]
How do I make a command line program that takes arguments?
2,335,989
<p>How can I make a command line, so I can execute my program on Windows with some parameters...</p> <p>For example:</p> <pre><code>C:/Program/App.exe -safemode </code></pre>
1
2010-02-25T17:11:28Z
2,336,214
<p>I sense that you also want to generate an 'executable' that you can run standalone.... For that you use <a href="http://www.py2exe.org/" rel="nofollow">py2exe</a></p> <p>Here is a complete <code>example.py</code>:</p> <pre><code>import optparse parser = optparse.OptionParser() parser.add_option("-s", "--safemode...
7
2010-02-25T17:38:31Z
[ "python", "windows", "command-line" ]
How do I make a command line program that takes arguments?
2,335,989
<p>How can I make a command line, so I can execute my program on Windows with some parameters...</p> <p>For example:</p> <pre><code>C:/Program/App.exe -safemode </code></pre>
1
2010-02-25T17:11:28Z
2,336,753
<p>You are asking a question that has several levels of answers.</p> <p>First, command line is passed into the array sys.argv. argv is a historic name from C and Unix languages. So:</p> <pre><code>~/p$ cat &gt; args.py import sys print "You have ", len(sys.argv), "arguments." for i in range(len(sys.argv)): print "a...
0
2010-02-25T18:56:59Z
[ "python", "windows", "command-line" ]