Q_Id int64 337 49.3M | CreationDate stringlengths 23 23 | Users Score int64 -42 1.15k | Other int64 0 1 | Python Basics and Environment int64 0 1 | System Administration and DevOps int64 0 1 | Tags stringlengths 6 105 | A_Id int64 518 72.5M | AnswerCount int64 1 64 | is_accepted bool 2
classes | Web Development int64 0 1 | GUI and Desktop Applications int64 0 1 | Answer stringlengths 6 11.6k | Available Count int64 1 31 | Q_Score int64 0 6.79k | Data Science and Machine Learning int64 0 1 | Question stringlengths 15 29k | Title stringlengths 11 150 | Score float64 -1 1.2 | Database and SQL int64 0 1 | Networking and APIs int64 0 1 | ViewCount int64 8 6.81M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2,889,561 | 2010-05-22T19:55:00.000 | 0 | 0 | 0 | 0 | python,flash,firefox,bash,browser | 2,889,576 | 2 | false | 0 | 0 | i think this might do it if you put it in the initialization part:
Stage["displayState"]="fullScreen"; | 1 | 0 | 0 | I have a swf file (a flash game). I want to run some script to open it in full-screen mode. I'm not attached to any browser, but I do run Linux, so a bash, or generic answer is what I'm looking for. I'm also open to building a lite browser application if need-be. | Launch an SWF full screen | 0 | 0 | 0 | 990 |
2,890,564 | 2010-05-23T03:10:00.000 | 1 | 0 | 0 | 0 | python,matplotlib,sqlalchemy | 2,891,001 | 1 | true | 0 | 0 | It looks like matplotlib takes simple python data types -- lists of numbers, etc, so you'll be need to write custom code to massage what you pull out of mysql/sqlalchemy for input into the graphing functions... | 1 | 1 | 0 | After running a bunch of simulations I'm going to be outputting the results into a table created using SQLAlchemy. I plan to use this data to generate statistics - mean and variance being key. These, in turn, will be used to generate some graphs - histograms/line graphs, pie-charts and box-and-whisker plots specifically.
I'm aware of the Python graphing libraries like matplotlib. The thing is, I'm not sure how to have this integrate with the information contained within the database tables.
Any suggestions on how to make these two play with each other?
The main problem is that I'm not sure how to supply the information as "data sets" to the graphing library. | How to generate graphs and statistics from SQLAlchemy tables? | 1.2 | 1 | 0 | 1,415 |
2,891,017 | 2010-05-23T07:56:00.000 | 3 | 1 | 0 | 0 | java,php,python,ruby-on-rails,django | 2,891,024 | 2 | true | 1 | 0 | If you only know PHP and you don't feel like learning Ruby/Python/Java. Seriously, if it can be done better with another tool, it should be done with another tool. Of course, this assumes the other tools are actually better. That part is arguable. Some people are so stuck up on their "my way is the best way" that they leave out the "because it's the only way I know" part. | 1 | 1 | 0 | We have discussion in my job place about question (We use 1 of the php frameworks):
Why program with php frameworks big web application if it can be done better with ruby on rails, python or java?
Please say our opinion
thanks | Why program with php frameworks if it can be done better with ruby on rails, python or java? | 1.2 | 0 | 0 | 240 |
2,891,493 | 2010-05-23T11:22:00.000 | 0 | 0 | 1 | 0 | python,dll,shared-libraries,ctypes | 27,273,719 | 8 | false | 0 | 0 | Internally ctypes uses functions provided by dynamic link library (dlopen/dlsym on unix, LoadLibrary/GetProcAddress on windows) to load library and find address of function specified by function name; and then use cffi library to pass parameter dynamically.
Problem is that the dynamic link library that ctypes depends on doesn't include function to list symbol from the shared library, that's why you can't list symbol by ctypes.
To do that, you have to use specific tools to dump elf file (readelf on unix) and pe file for dll (dumpbin on windows). | 1 | 45 | 0 | Is there any way to know which functions are exported from the dll through python foreign function library ctypes?
And if possible to know details about the exported functions through ctypes.
If yes, could someone provide a snippet of code? | list exported functions from dll with ctypes | 0 | 0 | 0 | 48,922 |
2,892,746 | 2010-05-23T17:44:00.000 | -2 | 0 | 1 | 0 | python,generator,pdb | 2,892,917 | 2 | false | 0 | 0 | In debuggers, generally you want to "step" (s) into a function in this case, rather than "next" (n).
"Next" executes the next line in the scope you're looking at; "step" brings you into the next scope down, the generator in this case, which sounds like what you want to do. | 1 | 5 | 0 | When in the Python debugger (pdb) I want to step over a yield statement, but hitting (n) for next brings me to the destination of the yield i.e. the consumer of the generator. I want to go to the next line that is executed within the generator. Is there any way to do this?
I'm using Python 2.6 | Stepping over a yield statement | -0.197375 | 0 | 0 | 1,343 |
2,893,033 | 2010-05-23T19:06:00.000 | 4 | 0 | 0 | 1 | python,linux,centos | 2,893,047 | 1 | true | 0 | 0 | What's dns.__file__ in the first case? I suspect it's not coming from the directory you cded into the second time (the current directory when you start Python goes at the front of sys.path) but rather from a package containing that crucial resolver module which the second one appears to be lacking. | 1 | 2 | 0 | Very strange for me:
# uname -a
Linux localhost.localdomain 2.6.18-194.3.1.el5 #1 SMP Thu May 13 13:09:10 EDT 2010 i686 i686 i386 GNU/Linux
# pwd
/root
# python
Python 2.6.5 (r265:79063, Apr 11 2010, 22:34:44)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dns
>>>
[3]+ Stopped python
# cd /home/user/dev/dns
[root@localhost dns]# python
Python 2.6.5 (r265:79063, Apr 11 2010, 22:34:44)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dns
Traceback (most recent call last):
File "", line 1, in
File "dns.py", line 1, in
import dns.resolver
ImportError: No module named resolver
>>>
[4]+ Stopped python
#
Summary: I can't import same python module from different path.
Any ideas? 0_o
P.S. SELINUX=disabled | Python modules import error | 1.2 | 0 | 0 | 2,669 |
2,893,313 | 2010-05-23T20:29:00.000 | 7 | 1 | 1 | 0 | python,scheme,code-translation | 2,893,338 | 5 | false | 0 | 0 | I would treat the original language implementation almost like a requirements specification, and write up a design based on it (most importantly including detailed interface definitions, both for the external interfaces and for those between modules within the library). Then I would implement from that design.
What I would most definitely NOT do is any kind of function-by-function translation. | 3 | 5 | 0 | Reasoning: I'm trying to convert a large library from Scheme to Python
Are there any good strategies for doing this kind of conversion? Specifically cross-paradigm in this case since Python is more OO and Scheme is Functional.
Totally subjective so I'm making it community wiki | Advice on translating code from very unrelated languages (in this case Scheme to Python)? | 1 | 0 | 0 | 193 |
2,893,313 | 2010-05-23T20:29:00.000 | 0 | 1 | 1 | 0 | python,scheme,code-translation | 2,893,602 | 5 | false | 0 | 0 | If you don't have time to do as the others have suggested and actually re-implement the functionality, there is no reason you CAN'T implement it in a strictly functional fashion.
Python supports the key features necessary to do functional programming, and you might find that your time was better spent doing other things, especially if absolute optimization is not required. On the other hand, you might find bug-hunting to be quite hard. | 3 | 5 | 0 | Reasoning: I'm trying to convert a large library from Scheme to Python
Are there any good strategies for doing this kind of conversion? Specifically cross-paradigm in this case since Python is more OO and Scheme is Functional.
Totally subjective so I'm making it community wiki | Advice on translating code from very unrelated languages (in this case Scheme to Python)? | 0 | 0 | 0 | 193 |
2,893,313 | 2010-05-23T20:29:00.000 | 1 | 1 | 1 | 0 | python,scheme,code-translation | 2,893,563 | 5 | false | 0 | 0 | I would setup a bunch of whiteboards and write out the algorithms from the Scheme code. Then I would implement the algorithms in Python. Then, as @PaulHankin suggests, use the Scheme code as a way to write test cases to test the Python code | 3 | 5 | 0 | Reasoning: I'm trying to convert a large library from Scheme to Python
Are there any good strategies for doing this kind of conversion? Specifically cross-paradigm in this case since Python is more OO and Scheme is Functional.
Totally subjective so I'm making it community wiki | Advice on translating code from very unrelated languages (in this case Scheme to Python)? | 0.039979 | 0 | 0 | 193 |
2,893,686 | 2010-05-23T22:09:00.000 | 9 | 0 | 1 | 0 | python | 2,893,714 | 3 | false | 0 | 0 | Python bytecode requires Python to run, cannot be ran standalone without Python, and is specific to a particular x.y release of Python. It should be portable across platforms for the same version. There is not a common reason for you to use it; Python uses it to optimize out parsing of your .py file on repeated imports. Your life will be fine ignoring the existence of pyc files. | 1 | 14 | 0 | I want to know what a pyc file(python bytecode) is. I want to know all the details.
I want to know about how pyc files interface with the compiler. Is it a replacement for exe?
Does it need to be run by python?
Is it as portable as the .py file is?
Where should I use this? | Where to use a pyc file | 1 | 0 | 0 | 9,508 |
2,894,235 | 2010-05-24T01:07:00.000 | 0 | 0 | 1 | 0 | python,import,modular | 2,896,137 | 5 | false | 0 | 0 | Alex's answer and the others cover the general case.
However, since these modules you're working on are your own and you'll edit only them, it's possible to implement some kind of a local reloading mechanism rather than rely on the builtin reload. You can architect your module loader as something that loads up the files, compiles it and evals them into a specific namespace and tells the calling code that it's ready. You can take care of reloading by making sure that there's a decent init function which reinitialises the module properly. I assume you'll be editing only these.
It's a bit of work but might be interesting and worth your time. | 1 | 2 | 0 | scenario: a modular app that loads .py modules on the fly as it works. programmer (me) wishes to edit the code of a module and then re-load it into the program without halting execution.
can this be done?
i have tried running import a second time on an updated module.py, but the changes are not picked up | how do i edit a running python program? | 0 | 0 | 0 | 325 |
2,894,344 | 2010-05-24T01:41:00.000 | 0 | 0 | 0 | 0 | python,django,macos | 2,901,051 | 2 | false | 1 | 0 | Okay, so this is very bizarre and I don't know what happened... but here's what fixed:
I open terminal and bash isn't recognizing any commands (python, vi, etc)
I restart machine, still not recognizing any commands
I look at my $PATH and /usr/bin is missing
I add /usr/bin to $PATH
I open vi and modify my profile to add /usr/bin
vi works, python works
python manage.py runserver works
How did /usr/bin get removed from my bash profile? | 1 | 1 | 0 | I've been developing a Django app for weeks locally on OSX 10.6.3. Recently, I rebooted my machine and went to start my development environment up.
Here's the error:
cm:myApp cm$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 11, in execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/init.py", line 360, in execute_manager
setup_environ(settings_mod)
File "/Library/Python/2.6/site-packages/django/core/management/init.py", line 343, in setup_environ
project_module = import_module(project_name)
File "/Library/Python/2.6/site-packages/django/utils/importlib.py", line 35, in import_module
import(name)
ImportError: No module named myapp
I'm pretty new to Django / Python.
Digging around, it's possible that this might be due to MacPorts. Initially, I had a rough time getting Django up and running and I no longer remember if I'm using the Django from a MacPorts install or from easy_install. How do I tell? (I'd prefer not to reinstall everything).
Also, why is the camel casing in my app name gone in the ImportError message? When I search for "myapp" in my django project, I don't find it without camelcase anywhere.
And what causes MacPorts to work for a while but then break?
As a few other details, from settings.py:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'south',
'registration',
'pypaypal',
'notifier',
'myApp.batches',
) | manage.py runserver throws an ImportError with my appname, MacPorts issue on OSX? | 0 | 0 | 0 | 2,460 |
2,894,802 | 2010-05-24T04:53:00.000 | 3 | 0 | 0 | 0 | python,django,django-registration | 17,230,981 | 4 | false | 1 | 0 | EMAIL_PORT = 465 was working some year ago. Now you need to use port 587 with gmail.
Reason: Django does not support SMTP with SSL from the beginning. Only STARTTLS command is supported AFTER plain-text connection is set up. Gmail, however, no longer supports this option on port 465. | 2 | 8 | 0 | I am curious if there's a way to send activated email with username, password by using django-registration. First I thought about modifying registration form but I need some example. | send activate-email with django-registration | 0.148885 | 0 | 0 | 11,049 |
2,894,802 | 2010-05-24T04:53:00.000 | 2 | 0 | 0 | 0 | python,django,django-registration | 31,984,785 | 4 | false | 1 | 0 | Hope this will help someone. After troubleshooting for half an hour, I realised that I had to explicitly state this as well while using django-registration -
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' | 2 | 8 | 0 | I am curious if there's a way to send activated email with username, password by using django-registration. First I thought about modifying registration form but I need some example. | send activate-email with django-registration | 0.099668 | 0 | 0 | 11,049 |
2,894,914 | 2010-05-24T05:26:00.000 | 0 | 0 | 0 | 0 | python,django,apache | 2,894,962 | 4 | false | 1 | 0 | apache has a server setting for max file size..(also dont forget max post size). I do not believe apache can show an error page on its own, you can probably use python for that.
unfortunetly I know nothing obout python (yet) so I can't really help you beyond that.
I know php can do that easily so I'm sure there is a method for python. | 1 | 1 | 0 | How to restrict the size of file being uploaded.
I am using django 1.1 with apache.
Can I use apache for this and show some html error page if say size is bigger then 100MB.
Thanks. | How to restrict the size of file being uploaded apache + django | 0 | 0 | 0 | 4,866 |
2,895,187 | 2010-05-24T06:36:00.000 | 0 | 1 | 0 | 0 | python,inotify,pyinotify | 22,093,028 | 3 | false | 0 | 0 | Why don't you add a dummy file at the end of the transfer? You can use the IN_CLOSE or IN_CREATE event code on the dummy. The important thing is that the dummy as to be transfered as the last file in the sequence.
I hope it'll help. | 1 | 4 | 0 | for large files or slow connections, copying files may take some time.
using pyinotify, i have been watching for the IN_CREATE event code. but this seems to occur at the start of a file transfer. i need to know when a file is completely copied - it aint much use if it's only half there.
when a file transfer is finished and completed, what inotify event is fired? | which inotify event signals the completion of a large file operation? | 0 | 0 | 0 | 4,934 |
2,895,397 | 2010-05-24T07:22:00.000 | 2 | 0 | 0 | 1 | python,google-app-engine | 2,940,702 | 2 | false | 1 | 0 | If your administrator is an Apps for Domains account (eg, @yourdomain.com), and your app uses Google Accounts authentication, you won't be able to authenticate as an admin on your app. You need to add a Google Accounts (eg, @google.com) account as an administrator, and use that to upload. | 1 | 3 | 0 | I am using appcfg.py to upload data to datastore from a csv file.
But every time I try, I am getting error:
[info ] Authentication failed
even if i am using Admin id and password.
In my app.yaml file I am having:
handlers:
- url: /remote_api
script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
login: admin
- url: .*
script: MainHandler.py
Can anybody please help me?
Thanks in advance. | Google App Engine appcfg.py data_upload Authentication fail | 0.197375 | 0 | 0 | 1,823 |
2,896,490 | 2010-05-24T11:11:00.000 | 4 | 0 | 0 | 0 | python,django,admin,overriding | 3,166,408 | 3 | true | 1 | 0 | You can use template hierarchy like:
index.html
...
{% block content %}
...
{% block mycontent %}My custom text{% endblock %}
...
{% endblock %}
app_index.html
...
{% block mycontent %}{% endblock %}
.. | 1 | 3 | 0 | I'm trying to add features to Django 1.2 admin's main page.
I've been playing with index.html, but features added to this page affect all app pages.
Any ideas on what template I'm supposed to use?
Thanks loads!! | Overriding Django Admin's main page? - Django | 1.2 | 0 | 0 | 8,486 |
2,898,685 | 2010-05-24T16:58:00.000 | 3 | 0 | 1 | 0 | python,salt,sha,hashlib,saltedhash | 15,399,755 | 6 | false | 0 | 0 | use passlib, writing your own password crypto is an almost sure way to failure. | 1 | 45 | 0 | I have been looking through ths hashlib documentation but haven't found anything talking about using salt when hashing data.
Help would be great. | Hashing in SHA512 using a salt? - Python | 0.099668 | 0 | 0 | 75,624 |
2,899,907 | 2010-05-24T20:03:00.000 | 2 | 0 | 0 | 0 | python,browser,python-webbrowser | 2,899,946 | 5 | false | 0 | 0 | You need to use something that the current browsers support, this means you're stuck with Flash, Java applets or Javascript+HTML if you want your game displayed in a browser.
You can use python on the backend and display pure HTML, if that is enough for your needs. | 3 | 12 | 0 | is it possible to use python to create flash like browser games? (Actually I want to use it for an economic simulation, but it amounts to the same as a browser game)
Davoud | Can I use python to create flash like browser games? | 0.07983 | 0 | 0 | 32,924 |
2,899,907 | 2010-05-24T20:03:00.000 | 1 | 0 | 0 | 0 | python,browser,python-webbrowser | 2,899,951 | 5 | false | 0 | 0 | Yes, but there a a number of ways to get there.
Flash is the client side rendering. You could use Python to generate Flash, or you could use Python to generate some dynamic HTML with Javascript, etc. that was interactive in a similar way.
But the Python will be running on the server. The Flash, ActionScript, HTML, JavaScript, etc. will all be running on the client.
So while the answer to the question is yes, I am going to suggest you might need to do more research and ask a better question. | 3 | 12 | 0 | is it possible to use python to create flash like browser games? (Actually I want to use it for an economic simulation, but it amounts to the same as a browser game)
Davoud | Can I use python to create flash like browser games? | 0.039979 | 0 | 0 | 32,924 |
2,899,907 | 2010-05-24T20:03:00.000 | 1 | 0 | 0 | 0 | python,browser,python-webbrowser | 2,899,983 | 5 | false | 0 | 0 | You could have Python CGI code as a backend and send input in to it through AJAX. Its probably better just use something on the client side for this, though. | 3 | 12 | 0 | is it possible to use python to create flash like browser games? (Actually I want to use it for an economic simulation, but it amounts to the same as a browser game)
Davoud | Can I use python to create flash like browser games? | 0.039979 | 0 | 0 | 32,924 |
2,900,358 | 2010-05-24T21:11:00.000 | 3 | 0 | 1 | 0 | python,matlab,mlabwrap | 2,900,462 | 1 | true | 0 | 0 | Never mind. I found out how. Use mlab.addpath(). | 1 | 2 | 0 | I tried to use mlab.path(path,'/my/path') but failed. Got NameError: name 'path' is not defined in python. Anyone has an idea? | how to set MATLABPATH in Python and using mlabwrap? | 1.2 | 0 | 0 | 408 |
2,901,082 | 2010-05-24T23:38:00.000 | 2 | 0 | 1 | 0 | python,string,gettext,string-formatting | 2,901,194 | 2 | false | 0 | 0 | Don't have incorrectly spelled variable names - that's what testing is for.
On the face of it, displaying something seems better than throwing an exception, but sooner or later one of those mistranslations is bound to cause offence to some user.
.format() is the way to go these days.
Reconsider passing locals() straight into the translation. It will save you worrying about what happens if someone works out a way to do something sneaky with self in one of the translations. | 2 | 2 | 0 | Looking for best practice advice on what string substitution technique to use when using gettext(). Or do all techniques apply equally?
I can think of at least 3 string techniques:
1) Classic "%" based formatting:
"My name is %(name)s" % locals()
2) .format() based formatting:
"My name is {name}".format( locals() )
3) string.Template.safe_substitute()
import string
template = string.Template( "My name is ${name}" )
template.safe_substitute( locals() )
The advantage of the string.Template technique is that a translated string with with an incorrectly spelled variable reference can still yield a usable string value while the other techniques unconditionally raise an exception. The downside of the string.Template technique appears to be the inability for one to customize how a variable is formatted (padding, justification, width, etc). | Best practice for string substitution with gettext using Python | 0.197375 | 0 | 0 | 2,170 |
2,901,082 | 2010-05-24T23:38:00.000 | 3 | 0 | 1 | 0 | python,string,gettext,string-formatting | 2,901,181 | 2 | true | 0 | 0 | Actually I would prefer to get an exception during my tests, to fix the error as soon as possible -- "errors should not pass silently". So I consider that approach (2) is the best one in modern Python (which supports the readable and flexible format), and approach (1) a probably inevitable fall-back if you're stuck supporting older Python releases (where % was "the" way to do flexible formatting -- finding, or coding, some backport of format would be the main alternative). | 2 | 2 | 0 | Looking for best practice advice on what string substitution technique to use when using gettext(). Or do all techniques apply equally?
I can think of at least 3 string techniques:
1) Classic "%" based formatting:
"My name is %(name)s" % locals()
2) .format() based formatting:
"My name is {name}".format( locals() )
3) string.Template.safe_substitute()
import string
template = string.Template( "My name is ${name}" )
template.safe_substitute( locals() )
The advantage of the string.Template technique is that a translated string with with an incorrectly spelled variable reference can still yield a usable string value while the other techniques unconditionally raise an exception. The downside of the string.Template technique appears to be the inability for one to customize how a variable is formatted (padding, justification, width, etc). | Best practice for string substitution with gettext using Python | 1.2 | 0 | 0 | 2,170 |
2,902,320 | 2010-05-25T05:51:00.000 | 5 | 0 | 0 | 1 | python,twisted,m2crypto,pyopenssl | 2,905,513 | 2 | true | 0 | 0 | Neither pyOpenSSL nor M2Crypto exposes OpenSSL's DTLS features (as far as I know). So, the first step would be to extend one of these libraries to support it. After that, you could extend Twisted to use the new features you just added to the underlying SSL library. | 1 | 2 | 0 | How to implement dtls protocol using twisted with m2crypto (or pyopenssl)? | Twisted DTLS connection | 1.2 | 0 | 0 | 1,465 |
2,903,507 | 2010-05-25T09:41:00.000 | 1 | 0 | 1 | 1 | python,deployment | 2,903,621 | 2 | false | 0 | 0 | May be you should try to make your application running standalone with py2exe or pyInstaller.
It will generate an application which doesn't expect anything from the target machine. You 'll have an exe file that the user can execute without knowing that Python is used. The Python interpreter and the needed libs will be included.
Then you can use Inno Setup to make a windows installer that will copy all the needed files.
I am not sure if Django is very easy to include in such a standalone version.
I hope it helps | 1 | 0 | 0 | My application uses many Python libraries (Django, Twisted, xmlrpc). I cannot expect that the end user has the Python installed with all needed libraries.
I've created a fancy installer for my application using Inno Setup, but I don't think that it is a good solution to execute 5 other setup programs from my installer. It would be annoying to the user to click "Next" button 15 times. Is there any way to do that quietly? | installing Python application with Python under windows | 0.099668 | 0 | 0 | 220 |
2,903,827 | 2010-05-25T10:36:00.000 | 1 | 0 | 1 | 0 | java,python,exception | 2,903,876 | 6 | false | 0 | 0 | It's just naming. In Java, you have java.lang.Error distinct from other Throwables because those kinds of errors need to be unchecked. In Python, all exceptions are unchecked, so the distinction is kind of pointless. | 3 | 85 | 0 | Why are Python exceptions named "Error" (e.g. ZeroDivisionError, NameError, TypeError)
and not "Exception" (e.g. ZeroDivisionException, NameException, TypeException).
I come from a Java background and started to learn Python recently, as such this is confusing because in Java there is a distinction between errors and exceptions.
Is there a difference in Python also or not? | Why are Python exceptions named "Error"? | 0.033321 | 0 | 0 | 17,771 |
2,903,827 | 2010-05-25T10:36:00.000 | 100 | 0 | 1 | 0 | java,python,exception | 2,903,946 | 6 | false | 0 | 0 | You don't name each class with 'Class' in name and each variable with '_variable' in name. The same way you don't name exception using the word 'Exception'. A name should say something about the meaning of an object. 'Error' is the meaning of most exceptions.
Not all Exceptions are Errors. SystemExit, KeyboardInterrupt, StopIteration, GeneratorExit are all exceptions and not errors. The word 'Error' in actual errors shows the difference.
'Error' is shorter than 'Exception'. That can save a few characters in the code width with no loss in meaning. That makes some difference. | 3 | 85 | 0 | Why are Python exceptions named "Error" (e.g. ZeroDivisionError, NameError, TypeError)
and not "Exception" (e.g. ZeroDivisionException, NameException, TypeException).
I come from a Java background and started to learn Python recently, as such this is confusing because in Java there is a distinction between errors and exceptions.
Is there a difference in Python also or not? | Why are Python exceptions named "Error"? | 1 | 0 | 0 | 17,771 |
2,903,827 | 2010-05-25T10:36:00.000 | 9 | 0 | 1 | 0 | java,python,exception | 2,903,973 | 6 | false | 0 | 0 | Python is fairly similar to Java in this respect. But Python's Exception should be compared to Java's Throwable.
As Throwables come in all kinds of flavors - Error, RuntimeException and (checked) Exception - so do Python's (though no checked exceptions).
As for the language, an Error is exceptional, so that inheritance hierarchy is not strange.
I don't particularly like the name Exception though. Exceptions are not only used for exceptional circumstances (like hopefully Errors) but also to just get out of the control flow. Because that is what a Exception does; it jumps out of the normal flow of control to a marked point. A bit like a goto, but more refined.
That said, every time you have a situation in which no suitable return value can be found you tend to use an Exception. Both in Python as in Java. | 3 | 85 | 0 | Why are Python exceptions named "Error" (e.g. ZeroDivisionError, NameError, TypeError)
and not "Exception" (e.g. ZeroDivisionException, NameException, TypeException).
I come from a Java background and started to learn Python recently, as such this is confusing because in Java there is a distinction between errors and exceptions.
Is there a difference in Python also or not? | Why are Python exceptions named "Error"? | 1 | 0 | 0 | 17,771 |
2,905,097 | 2010-05-25T13:35:00.000 | 0 | 0 | 0 | 0 | python,postgresql | 2,906,866 | 7 | false | 0 | 0 | I agree with the SQL Alchemy suggestions or using Django's ORM. Your needs seem to simple for PL/Python to be used. | 1 | 4 | 0 | If you wanted to manipulate the data in a table in a postgresql database using some python (maybe running a little analysis on the result set using scipy) and then wanted to export that data back into another table in the same database, how would you go about the implementation?
Is the only/best way to do this to simply run the query, have python store it in an array, manipulate the array in python and then run another sql statement to output to the database?
I'm really just asking, is there a more efficient way to deal with the data?
Thanks,
Ian | Python and Postgresql | 0 | 1 | 0 | 1,582 |
2,905,948 | 2010-05-25T15:12:00.000 | 0 | 1 | 0 | 0 | python,mako | 2,946,762 | 2 | true | 1 | 0 | I don't think you're likely to find such a thing. Like all the other fast python template engines, Mako achieves its speed by compiling your template into python code and then executing it. An exception will divert execution out of your template's code, so by the time one is raised, that template will have no way of displaying it (or doing anything else for that matter).
As an alternative, I suggest putting your template rendering code inside a try block, and rendering any caught exceptions with a separate template used specifically for that purpose. | 2 | 2 | 0 | Is there a way to add tempate string which contains error to mako`s error trace? | Better error reporting mako | 1.2 | 0 | 0 | 198 |
2,905,948 | 2010-05-25T15:12:00.000 | 0 | 1 | 0 | 0 | python,mako | 9,271,873 | 2 | false | 1 | 0 | I was looking for another error I have and found this. I though it would be nice if you still ever need this, you can achieve it by setting mako.strict_undefined = True. I am using mako-0.6.2 so it may not been possible in the version back in 2010. | 2 | 2 | 0 | Is there a way to add tempate string which contains error to mako`s error trace? | Better error reporting mako | 0 | 0 | 0 | 198 |
2,906,790 | 2010-05-25T17:12:00.000 | 0 | 0 | 0 | 0 | python,django,session | 2,907,043 | 3 | false | 1 | 0 | You're not asking about sessions, you're asking about requests. What you want is known as throttling. However, it would be quite difficult to do it inside the app, because Apache manages multiple processes and threads, so you'd need some external process to keep track of these in order to enable the throttling.
Basically, this sort of thing is best done within Apache itself, by something like mod_throttle. | 1 | 2 | 0 | How can I fix number of concurrent sessions allowed at app level?
Basically I want a limit to how many concurrent requests to this url to keep the server from getting congested.
I guess some middleware hack?
Thanks. | way to fix number of concurrent sessions allowed at app level. django | 0 | 0 | 0 | 201 |
2,907,087 | 2010-05-25T17:47:00.000 | 1 | 1 | 0 | 0 | javascript,c++,python,scripting,embedding | 5,080,151 | 5 | false | 0 | 0 | Have a look at angelscript
simple and easy to embed, c/c++ like syntax. free and corss-platform. u can get start in a few hrs. | 2 | 4 | 0 | I'm researching how to best extend a C++ application with scripting capability, and I am looking at either Python or JavaScript. User-defined scripts will need the ability to access the application's data model.
Have any of you had experiences with embedding these scripting engines? What are some potential pitfalls? | Embedding a scripting engine in C++ | 0.039979 | 0 | 0 | 2,816 |
2,907,087 | 2010-05-25T17:47:00.000 | 7 | 1 | 0 | 0 | javascript,c++,python,scripting,embedding | 2,907,217 | 5 | false | 0 | 0 | Lua is also a great candidate for embedding in programs. Its very self contained, and even the native cross-language call system isn't bad.
For JavaScript, your best bet right now is to look at V8 (from Google), which is easy enough to work with. | 2 | 4 | 0 | I'm researching how to best extend a C++ application with scripting capability, and I am looking at either Python or JavaScript. User-defined scripts will need the ability to access the application's data model.
Have any of you had experiences with embedding these scripting engines? What are some potential pitfalls? | Embedding a scripting engine in C++ | 1 | 0 | 0 | 2,816 |
2,907,498 | 2010-05-25T18:43:00.000 | 0 | 0 | 0 | 0 | python,metaprogramming | 2,907,750 | 5 | false | 1 | 0 | SQLalchemy also uses them for declarative database models.
Sorry my answer isn't very different from your example, but if you're looking for example code, I found declarative to be pretty readable. | 1 | 13 | 0 | I'm learning about metaclasses in Python. I think it is a very powerful technique, and I'm looking for good uses for them. I'd like some feedback of good useful real-world examples of using metaclasses. I'm not looking for example code on how to write a metaclass (there are plenty examples of useless metaclasses out there), but real examples where you have applied the technique and it was really the appropriate solution. The rule is: no theoretical possibilities, but metaclasses at work in a real application.
I'll start with the one example I know:
Django models, for declarative programming, where the base class Model uses a metaclass to fill the model objects of useful ORM functionality from the attribute definitions.
Looking forward to your contributions. | Good real-world uses of metaclasses (e.g. in Python) | 0 | 0 | 0 | 2,053 |
2,907,864 | 2010-05-25T19:28:00.000 | 0 | 0 | 0 | 1 | python,linux,shell,process | 2,907,901 | 2 | false | 0 | 0 | Writing to *argv will change it, but you'll need to do that from C or the like; I don't think Python is going to readily give you access to that memory directly.
I'd also recommend just leaving it alone. | 2 | 3 | 0 | I'm using Python, for what it's worth, but will accept answers in any applicable language.
I've tried writing to /proc/$pid/cmdline, but that's a readonly file.
I've tried assigning a new string to sys.argv[0], but that has no perceptible impact.
Are there any other possibilities? My program is executing processes via os.system (equivalent to system(3)) so a general, *NIX-based solution using an additional spawning process would be fine. | How do I rename a process on Linux? | 0 | 0 | 0 | 4,944 |
2,907,864 | 2010-05-25T19:28:00.000 | 0 | 0 | 0 | 1 | python,linux,shell,process | 2,907,918 | 2 | false | 0 | 0 | If you use subprocess.Popen instead of os.system you can use the executable argument to specify the path to the actual file to execute, and pass the name you want to show as the first item in the list that is parameter args. | 2 | 3 | 0 | I'm using Python, for what it's worth, but will accept answers in any applicable language.
I've tried writing to /proc/$pid/cmdline, but that's a readonly file.
I've tried assigning a new string to sys.argv[0], but that has no perceptible impact.
Are there any other possibilities? My program is executing processes via os.system (equivalent to system(3)) so a general, *NIX-based solution using an additional spawning process would be fine. | How do I rename a process on Linux? | 0 | 0 | 0 | 4,944 |
2,908,440 | 2010-05-25T20:52:00.000 | 0 | 0 | 0 | 0 | python,lxml,celementtree | 2,908,479 | 3 | false | 0 | 0 | lxml is basically a superset of ElementTree so you could start with ElementTree and then if you have performance or functionality issues then you could change to lxml.
Performance issues can only be studied by you using your own data, | 1 | 4 | 0 | I am going to handle XML files for a project. I had earlier decided to use lxml but after reading the requirements, I think ElemenTree would be better for my purpose.
The XML files that have to be processed are:
Small in size. Typically < 10 KB.
No namespaces.
Simple XML structure.
Given the small XML size, memory is not an issue. My only concern is fast parsing.
What should I go with? Mostly I have seen people recommend lxml, but given my parsing requirements, do I really stand to benefit from it or would ElementTree serve my purpose better? | Which Python XML library should I use? | 0 | 0 | 1 | 372 |
2,909,423 | 2010-05-26T00:21:00.000 | 10 | 0 | 1 | 0 | python,shell,performance,getattr | 2,909,510 | 2 | false | 0 | 0 | does getattr have the same problems as eval?
No -- code using eval() is terribly annoying to maintain, and can have serious security problems. Calling getattr(x, "foo") is just another way to write x.foo.
will I be taking a hit to the efficiency of my shell
It will be imperceptibly slower if the command isn't found, but not enough to matter. You'd only notice it if doing benchmarks, with tens of thousands of entries. | 1 | 10 | 0 | I'm creating a shell-like environment. My original method of handleing user input was to use a dictionary mapping commands (strings) to methods of various classes, making use of the fact that functions are first class objects in python.
For flexibility's sake (mostly for parsing commands), I'm thinking of changing my setup such that I'm using getattr(command), to grab the method I need and then passing arguments to it at the end of my parser. Another advantage of this approach is not having to update my (currently statically implemented) command dictionary every time I add a new method/command.
My question is two fold. First, does getattr have the same problems as eval? Second, will I be taking a hit to the efficiency of my shell? Does it matter how many methods/commands I have? I'm currently looking at 30 some commands, which could eventually double. | Is it bad practice to use python's getattr extensively? | 1 | 0 | 0 | 6,796 |
2,909,605 | 2010-05-26T01:15:00.000 | 3 | 1 | 0 | 0 | python,mp3,lame,mutagen | 3,113,148 | 2 | true | 0 | 0 | The transformations done by the MP3 encoding process drop completely the concept of “bit depth”. You can only know the bit depth of the source audio if such information was stored in a tag of the MP3 file. Otherwise, you can take the MP3 data and produce 8-bit, 16-bit or 24-bit audio. | 1 | 1 | 0 | Is there a way to determine an MP3 file's encoded bit depth (ie 8, 16, 24, 32) in Python using the Mutagen library? | Determine MP3 bit depth in Python via Mutagen | 1.2 | 0 | 0 | 1,355 |
2,911,991 | 2010-05-26T10:16:00.000 | 1 | 0 | 0 | 0 | python,pyqt4,qlistview | 2,912,399 | 2 | false | 0 | 1 | Imho, an easier way to achieve this would be to use a QListWidget instead of a QListView, this way you could use the itemClicked signal, which sends the selected item to the callback function. | 1 | 1 | 0 | I have a working QListView, but from the documentation, I can't figure out how to get a signal to fire with the index of the newly selected item. Any ideas? | clicked() signal for QListView in PyQt4 | 0.099668 | 0 | 0 | 3,622 |
2,912,216 | 2010-05-26T10:52:00.000 | 2 | 1 | 0 | 1 | c#,python,ubuntu,mono | 2,912,360 | 2 | false | 0 | 0 | I cannot say much about the market for Ubuntu. And since business is your primary concern, the programming language is, as you say yourself, secondary. I would say that in any business, choose the language and tools that solves the business problem most effectively. When release comes do your end users really care?
That said, if you can do it with Mono/C# I would encourage you to do so since you already have C# and .Net experience. But knowing a second language and development environment will only make you stronger. | 1 | 2 | 0 | I'm a c# programmer by trade and looking to move my wares over to Ubuntu as a business concern. I have some experience of Python and like it a lot. My question is, as a developer which would be the best language to use when targeting ubuntu Mono c# or python as a commercial concern.
please note that I am not interested in the technical aspects but strictly the commercials of where Ubuntu is heading, I see that there is a lot of work done within using Python and thinking that maybe with the whole Mono issue of who "might" purchase them. | Which Language to target on Ubuntu? | 0.197375 | 0 | 0 | 309 |
2,912,615 | 2010-05-26T11:48:00.000 | -6 | 0 | 1 | 0 | python,arguments | 2,912,640 | 5 | false | 0 | 0 | I would use sed s/None//g, but that's not in python, but you can probably use os.popen() to do that. | 1 | 48 | 0 | I have a Python function accepting several string arguments def foo(a, b, c): and concatenating them in a string.
I want to iterate over all function arguments to check they are not None. How it can be done?
Is there a quick way to convert None to ""?
Thanks. | How to iterate over function arguments | -1 | 0 | 0 | 54,043 |
2,914,585 | 2010-05-26T15:52:00.000 | 0 | 0 | 1 | 1 | python,windows,visual-studio,dll,ctypes | 2,914,833 | 1 | true | 0 | 0 | I can load LibName64 when I use the 64 bit version of python. Should have tried that earlier! | 1 | 0 | 0 | Disclaimer: I'm new to windows programming so some of my assumptions may be wrong. Please correct me if so.
I am developing a python wrapper for a C API using ctypes. The API ships with both 64 and 32 DLLs/LIBs. I can succesfully load the DLL using ctypes.WinDLL('TheLibName') and call functions etc etc.
However some functions were not doing what they should. Upon further investigation it appears that the 32bit DLL is being used, which is what is causing the unexpected behaviour.
I have tried using ctypes.WinDLL('TheLibName64') but the module is not found. I have tried registering the DLL with regsrv32, but it reports there is no entry point (it also reports no entry point when I try and register TheLibName, which is found by WinDLL().
The DLL came with a sample project in Visual Studio (I have 0 experience with VS so again please correct me here) which builds both 32 and 64 bit versions of the sample project. In the .vcsproj file the configurations for the 64 bit version include:
AdditionalDependencies="TheLibName64.lib"
in the VCLinkerTool section.
In windows/system32 there are both TheLibName.dll/.lib, and TheLibName64.dll/.lib.
So it seems to me that my problem is now to make the python ctypes DLL loader load these optional dependencies when the DLL is loaded. However I can't find any information on this (perhaps because, as a doze noob, I do not know the correct terminology) in the ctypes documentation.
Is there a way to do this in ctypes? Am I going about this in completely the wrong way? Any help or general information about optional DLL dependencies and how they are loaded in windows would be much appreciated.
Thanks | ctypes DLL with optional dependencies | 1.2 | 0 | 0 | 971 |
2,914,816 | 2010-05-26T16:17:00.000 | 0 | 0 | 0 | 0 | python,wxpython,listctrl | 2,915,460 | 2 | false | 0 | 1 | Are you building on the wxPython demo code for virtual list controls? There are a couple of bookkeeping things you need to do, like set the ItemCount property.
One comment about your OnGetItemText method: Since there's no other return statement, it will return None if data is None, so your test has no effect.
How about return data or "" instead? | 2 | 2 | 0 | I'm rewriting this post to clarify some things and provide a full class definition for the Virtual List I'm having trouble with. The class is defined like so:
from wx import ListCtrl, LC_REPORT, LC_VIRTUAL, LC_HRULES, LC_VRULES, \
EVT_LIST_COL_CLICK, EVT_LIST_CACHE_HINT, EVT_LIST_COL_RIGHT_CLICK, \
ImageList, IMAGE_LIST_SMALL, Menu, MenuItem, NewId, ITEM_CHECK, Frame, \
EVT_MENU
class VirtualList(ListCtrl):
def __init__(self, parent, datasource = None,
style = LC_REPORT | LC_VIRTUAL | LC_HRULES | LC_VRULES):
ListCtrl.__init__(self, parent, style = style)
self.columns = []
self.il = ImageList(16, 16)
self.Bind(EVT_LIST_CACHE_HINT, self.CheckCache)
self.Bind(EVT_LIST_COL_CLICK, self.OnSort)
if datasource is not None:
self.datasource = datasource
self.Bind(EVT_LIST_COL_RIGHT_CLICK, self.ShowAvailableColumns)
self.datasource.list = self
self.Populate()
def SetDatasource(self, datasource):
self.datasource = datasource
def CheckCache(self, event):
self.datasource.UpdateCache(event.GetCacheFrom(), event.GetCacheTo())
def OnGetItemText(self, item, col):
return self.datasource.GetItem(item, self.columns[col])
def OnGetItemImage(self, item):
return self.datasource.GetImg(item)
def OnSort(self, event):
self.datasource.SortByColumn(self.columns[event.Column])
self.Refresh()
def UpdateCount(self):
self.SetItemCount(self.datasource.GetCount())
def Populate(self):
self.UpdateCount()
self.datasource.MakeImgList(self.il)
self.SetImageList(self.il, IMAGE_LIST_SMALL)
self.ShowColumns()
def ShowColumns(self):
for col, (text, visible) in enumerate(self.datasource.GetColumnHeaders()):
if visible:
self.columns.append(text)
self.InsertColumn(col, text, width = -2)
def Filter(self, filter):
self.datasource.Filter(filter)
self.UpdateCount()
self.Refresh()
def ShowAvailableColumns(self, evt):
colMenu = Menu()
self.id2item = {}
for idx, (text, visible) in enumerate(self.datasource.columns):
id = NewId()
self.id2item[id] = (idx, visible, text)
item = MenuItem(colMenu, id, text, kind = ITEM_CHECK)
colMenu.AppendItem(item)
EVT_MENU(colMenu, id, self.ColumnToggle)
item.Check(visible)
Frame(self, -1).PopupMenu(colMenu)
colMenu.Destroy()
def ColumnToggle(self, evt):
toggled = self.id2item[evt.GetId()]
if toggled[1]:
idx = self.columns.index(toggled[2])
self.datasource.columns[toggled[0]] = (self.datasource.columns[toggled[0]][0], False)
self.DeleteColumn(idx)
self.columns.pop(idx)
else:
self.datasource.columns[toggled[0]] = (self.datasource.columns[toggled[0]][0], True)
idx = self.datasource.GetColumnHeaders().index((toggled[2], True))
self.columns.insert(idx, toggled[2])
self.InsertColumn(idx, toggled[2], width = -2)
self.datasource.SaveColumns()
I've added functions that allow for Column Toggling which facilitate my description of the issue I'm encountering. On the 3rd instance of this class in my application the Column at Index 1 will not display String values. Integer values are displayed properly. If I add print statements to my OnGetItemText method the values show up in my console properly. This behavior is not present in the first two instances of this class, and my class does not contain any type checking code with respect to value display.
It was suggested by someone on the wxPython users' group that I create a standalone sample that demonstrates this issue if I can. I'm working on that, but have not yet had time to create a sample that does not rely on database access. Any suggestions or advice would be most appreciated. I'm tearing my hair out on this one. | wxPython ListCtrl Column Ignores Specific Fields | 0 | 0 | 0 | 1,183 |
2,914,816 | 2010-05-26T16:17:00.000 | 0 | 0 | 0 | 0 | python,wxpython,listctrl | 2,954,639 | 2 | true | 0 | 1 | There's a problem with the native object in Windows. If GetImg returns None instead of -1 the list has a problem with column 1 for some reason. That from Robin over on the Google Group post for this issue. | 2 | 2 | 0 | I'm rewriting this post to clarify some things and provide a full class definition for the Virtual List I'm having trouble with. The class is defined like so:
from wx import ListCtrl, LC_REPORT, LC_VIRTUAL, LC_HRULES, LC_VRULES, \
EVT_LIST_COL_CLICK, EVT_LIST_CACHE_HINT, EVT_LIST_COL_RIGHT_CLICK, \
ImageList, IMAGE_LIST_SMALL, Menu, MenuItem, NewId, ITEM_CHECK, Frame, \
EVT_MENU
class VirtualList(ListCtrl):
def __init__(self, parent, datasource = None,
style = LC_REPORT | LC_VIRTUAL | LC_HRULES | LC_VRULES):
ListCtrl.__init__(self, parent, style = style)
self.columns = []
self.il = ImageList(16, 16)
self.Bind(EVT_LIST_CACHE_HINT, self.CheckCache)
self.Bind(EVT_LIST_COL_CLICK, self.OnSort)
if datasource is not None:
self.datasource = datasource
self.Bind(EVT_LIST_COL_RIGHT_CLICK, self.ShowAvailableColumns)
self.datasource.list = self
self.Populate()
def SetDatasource(self, datasource):
self.datasource = datasource
def CheckCache(self, event):
self.datasource.UpdateCache(event.GetCacheFrom(), event.GetCacheTo())
def OnGetItemText(self, item, col):
return self.datasource.GetItem(item, self.columns[col])
def OnGetItemImage(self, item):
return self.datasource.GetImg(item)
def OnSort(self, event):
self.datasource.SortByColumn(self.columns[event.Column])
self.Refresh()
def UpdateCount(self):
self.SetItemCount(self.datasource.GetCount())
def Populate(self):
self.UpdateCount()
self.datasource.MakeImgList(self.il)
self.SetImageList(self.il, IMAGE_LIST_SMALL)
self.ShowColumns()
def ShowColumns(self):
for col, (text, visible) in enumerate(self.datasource.GetColumnHeaders()):
if visible:
self.columns.append(text)
self.InsertColumn(col, text, width = -2)
def Filter(self, filter):
self.datasource.Filter(filter)
self.UpdateCount()
self.Refresh()
def ShowAvailableColumns(self, evt):
colMenu = Menu()
self.id2item = {}
for idx, (text, visible) in enumerate(self.datasource.columns):
id = NewId()
self.id2item[id] = (idx, visible, text)
item = MenuItem(colMenu, id, text, kind = ITEM_CHECK)
colMenu.AppendItem(item)
EVT_MENU(colMenu, id, self.ColumnToggle)
item.Check(visible)
Frame(self, -1).PopupMenu(colMenu)
colMenu.Destroy()
def ColumnToggle(self, evt):
toggled = self.id2item[evt.GetId()]
if toggled[1]:
idx = self.columns.index(toggled[2])
self.datasource.columns[toggled[0]] = (self.datasource.columns[toggled[0]][0], False)
self.DeleteColumn(idx)
self.columns.pop(idx)
else:
self.datasource.columns[toggled[0]] = (self.datasource.columns[toggled[0]][0], True)
idx = self.datasource.GetColumnHeaders().index((toggled[2], True))
self.columns.insert(idx, toggled[2])
self.InsertColumn(idx, toggled[2], width = -2)
self.datasource.SaveColumns()
I've added functions that allow for Column Toggling which facilitate my description of the issue I'm encountering. On the 3rd instance of this class in my application the Column at Index 1 will not display String values. Integer values are displayed properly. If I add print statements to my OnGetItemText method the values show up in my console properly. This behavior is not present in the first two instances of this class, and my class does not contain any type checking code with respect to value display.
It was suggested by someone on the wxPython users' group that I create a standalone sample that demonstrates this issue if I can. I'm working on that, but have not yet had time to create a sample that does not rely on database access. Any suggestions or advice would be most appreciated. I'm tearing my hair out on this one. | wxPython ListCtrl Column Ignores Specific Fields | 1.2 | 0 | 0 | 1,183 |
2,915,945 | 2010-05-26T19:07:00.000 | 4 | 0 | 1 | 0 | python,drag-and-drop,executable | 2,915,964 | 1 | true | 0 | 0 | The dropped file will be available as an element of sys.argv. | 1 | 3 | 0 | I have a Python script that takes the directory path of a text file and converts it into an excel file. Currently I have it running as a console application (compiled with py2exe) and prompts the user for the directory path through raw_input().
How do i make it such that I can drag & drop my text file directly into the .exe of the python script? | Python - drag file into .exe to run script | 1.2 | 0 | 0 | 1,610 |
2,916,052 | 2010-05-26T19:20:00.000 | 0 | 0 | 0 | 0 | python,pyqt4 | 3,012,347 | 1 | true | 0 | 1 | The answer was to reimplement the resizeEvent and check table.horizontalScrollBar().isVisible() | 1 | 0 | 0 | I have a window with 2 QTableWidgets, having their scrolling synchronized.
The 1st one usually has horizontal scroll, while the 2nd usually (automatically) not.
In order for them to show consistent data (row against row) I make the 2nd have the scroll (through property HorizontalScrollBar -> AlwaysOn).
But sometimes the 1st table doesn't have the scroll. What's event worse, it may have it or not depending on the window size (when making window wider the scroll disappears). As far as I see there's no signal for resize of window or control (widget).
I can, of course, use some constantly running timer to check if 1st table has scroll, but I wounder if there's more pure solution.
Thanks! | Track window/control resize in PyQt? | 1.2 | 0 | 0 | 695 |
2,916,116 | 2010-05-26T19:30:00.000 | 1 | 0 | 1 | 0 | python,argparse | 2,916,155 | 3 | false | 0 | 0 | It would be best for the user to install it so that only one copy is present on the system and so that it can be updated if there are any issues, but including it with your project is a viable option if you abide by all requirements specified in the license.
Try to import it from the public location, and if that fails then resort to using the included module. | 1 | 2 | 0 | For my project I would be using the argparse library. My question is, how do I distribute it with my project. I am asking this because of the technicalities and legalities involved.
Do I just:
Put the argparse.py file along with
my project. That is, in the tar file for my project.
Create a package for it for my
distro?
Tell the user to install it himself? | Distributing a Python library (single file) | 0.066568 | 0 | 0 | 228 |
2,916,769 | 2010-05-26T21:00:00.000 | 1 | 0 | 1 | 0 | python,tiff | 12,981,385 | 3 | false | 0 | 0 | you can use the command utility "tiffutil" | 1 | 7 | 0 | I've found, via Google, numerous people asking the same question, but no solutions. The Python Image Library (PIL) has tools for stepping through an already existing multi-page TIFF, but nothing about creating them.
Libraries would hopefully be available on Windows, for Python 2.6.
If there's some freeware out there which will do the trick, I wouldn't mind seeing it, but I was hoping I could accomplish this in Python. | How Can I Programmatically Build a Multi-Page TIFF out of Many Single Page TIFFs, Using Python? | 0.066568 | 0 | 0 | 3,347 |
2,916,966 | 2010-05-26T21:30:00.000 | 2 | 0 | 0 | 0 | python,django,middleware,django-middleware | 33,104,799 | 9 | false | 1 | 0 | You can use process_view method, that is called before calling the view func. In process_view you can check — if this view requires this middleware interception. | 2 | 48 | 0 | In Django there is a settings file that defines the middleware to be run on each request. This middleware setting is global. Is there a way to specify a set of middleware on a per-view basis? I want to have specific urls use a set of middleware different from the global set. | Non-global middleware in Django | 0.044415 | 0 | 0 | 20,267 |
2,916,966 | 2010-05-26T21:30:00.000 | 1 | 0 | 0 | 0 | python,django,middleware,django-middleware | 18,391,612 | 9 | false | 1 | 0 | The best thing I've been able to find is using if request.path_info.startswith('...') to skip over the middleware by just returning the request. Now, you could create middleware just for the sake of skipping and then inherit that. Maybe you could do something even simpler and save that list in your settings.py and then skip all those. If I'm wrong in any way, let me know. | 2 | 48 | 0 | In Django there is a settings file that defines the middleware to be run on each request. This middleware setting is global. Is there a way to specify a set of middleware on a per-view basis? I want to have specific urls use a set of middleware different from the global set. | Non-global middleware in Django | 0.022219 | 0 | 0 | 20,267 |
2,917,687 | 2010-05-27T00:03:00.000 | 2 | 0 | 0 | 0 | python,django,fastcgi,django-urls | 2,955,645 | 2 | false | 1 | 0 | Django has a odd behaviour when matching urls in a environment that isn't under debug mode.
For example, with DEBUG=False, Django will ignore urls such as:
url(r'^', include('someapp.urls')),
specifically in the case above, you could let the string empty:
url(r'', include('someapp.urls')),
In other words, check your regexes.
Can you put your urls.py here to be analyzed? | 2 | 2 | 0 | We recently launched a new Django-powered website, and we are experiencing the oddest bug:
The site is running under Apache with mod_fastcgi. Everything works fine for a while, and then the URL tag and reverse() functionality stops working. Instead of returning the expected URL, they return "".
We haven't noticed anything in Apache's log file; there are no errors being generated by Django. And (the kicker) the problem only occurs in production mode; we can't reproduce it when DEBUG=True.
Any thoughts on where we should be looking for the problem?
Update: It turned out to be a problem with settings.LANGUAGES, although we haven't determined exactly why that broke things. | Django URL resolving infrastructure stops working | 0.197375 | 0 | 0 | 367 |
2,917,687 | 2010-05-27T00:03:00.000 | 7 | 0 | 0 | 0 | python,django,fastcgi,django-urls | 2,957,239 | 2 | true | 1 | 0 | This has happened to me before. Normally it's due to a 'broken' urls.py file. There are two things that make this kind of bug really hard to fix:
It could be the urls.py file in any of the apps that breaks the reverse() function, so knowing that reverse() breaks for app X doesn't mean the error is in that particular application's urls.py.
Django won't even notify you of errors in the urls.py file, unless you somehow manage to crash the site by doing something really, really nasty in the urls.py file.
Debugging: The way I go around fixing this is by manually disabling all applications (just comment out their line in INSTALLED_APPS) and checking reverse() works. If it still works, then I enable the next app, until it breaks. I know, very rudimentary stuff, but it works :) | 2 | 2 | 0 | We recently launched a new Django-powered website, and we are experiencing the oddest bug:
The site is running under Apache with mod_fastcgi. Everything works fine for a while, and then the URL tag and reverse() functionality stops working. Instead of returning the expected URL, they return "".
We haven't noticed anything in Apache's log file; there are no errors being generated by Django. And (the kicker) the problem only occurs in production mode; we can't reproduce it when DEBUG=True.
Any thoughts on where we should be looking for the problem?
Update: It turned out to be a problem with settings.LANGUAGES, although we haven't determined exactly why that broke things. | Django URL resolving infrastructure stops working | 1.2 | 0 | 0 | 367 |
2,917,974 | 2010-05-27T01:42:00.000 | 16 | 0 | 1 | 0 | python | 2,917,989 | 8 | false | 0 | 0 | How easy and convenient is python for scientific computing?
Scipy/NumPy.
Does it have a library of algorithms that compares to matlab's?
Yes.
Is Python a scripting language or does it compile?
Interpreted.
Is it a great language for prototyping an algorithm?
Yes.
How long would it take me to learn enough of it to be productive provided I know C well and OO programming somewhat?
Depends.
Is it OO based?
Yes. | 4 | 5 | 0 | My interests in programming lie mainly in algorithms, and lately I have seen many reputable researchers write a lot of their code in python. How easy and convenient is python for scientific computing? Does it have a library of algorithms that compares to matlab's? Is Python a scripting language or does it compile? Is it a great language for prototyping an algorithm? How long would it take me to learn enough of it to be productive provided I know C well and OO programming somewhat? Is it OO based?
Sorry for the condensed format of questions, but I'm very curious and was hoping a more experienced programmer could help me out. | Is Python appropriate for algorithms focused on scientific computing? | 1 | 0 | 0 | 1,053 |
2,917,974 | 2010-05-27T01:42:00.000 | 4 | 0 | 1 | 0 | python | 2,918,046 | 8 | false | 0 | 0 | I've used Python for 6 years for scientific computing. Having come from matlab/IDL, it was very easy to do the switch since it's also interpreted.
There are 3rd party tools such as SciPy and Matplotlib to help specifically with data analysis /visualization. Also, if you look in Amazon there are books targeting this audience.
Python is also very often used to teach programming because of it's simple yet powerful syntax. | 4 | 5 | 0 | My interests in programming lie mainly in algorithms, and lately I have seen many reputable researchers write a lot of their code in python. How easy and convenient is python for scientific computing? Does it have a library of algorithms that compares to matlab's? Is Python a scripting language or does it compile? Is it a great language for prototyping an algorithm? How long would it take me to learn enough of it to be productive provided I know C well and OO programming somewhat? Is it OO based?
Sorry for the condensed format of questions, but I'm very curious and was hoping a more experienced programmer could help me out. | Is Python appropriate for algorithms focused on scientific computing? | 0.099668 | 0 | 0 | 1,053 |
2,917,974 | 2010-05-27T01:42:00.000 | 1 | 0 | 1 | 0 | python | 2,918,335 | 8 | false | 0 | 0 | Is Python appropriate for algorithms focused on scientific computing?
Yes | 4 | 5 | 0 | My interests in programming lie mainly in algorithms, and lately I have seen many reputable researchers write a lot of their code in python. How easy and convenient is python for scientific computing? Does it have a library of algorithms that compares to matlab's? Is Python a scripting language or does it compile? Is it a great language for prototyping an algorithm? How long would it take me to learn enough of it to be productive provided I know C well and OO programming somewhat? Is it OO based?
Sorry for the condensed format of questions, but I'm very curious and was hoping a more experienced programmer could help me out. | Is Python appropriate for algorithms focused on scientific computing? | 0.024995 | 0 | 0 | 1,053 |
2,917,974 | 2010-05-27T01:42:00.000 | 1 | 0 | 1 | 0 | python | 2,925,531 | 8 | false | 0 | 0 | You asked about compiled/interpreted. If your concern here was execution speed, there is an aspect of python that doesn't seem to have been covered explicitly---you can use tools like SWIG and boost.python to make your lightning fast C/C++ packages appear in your python as modules. Once you get to the module, it will run at the speed/efficiency of the underlying C/C++ implementation. Many modules are available that take advantage of this.
So, you get to do all the organizational stuff in clear, flexible, easy to learn Python, and then when you get to your heavy number crunching, you get to hand off the problem to a fast, efficient routine. You get the best of both worlds. | 4 | 5 | 0 | My interests in programming lie mainly in algorithms, and lately I have seen many reputable researchers write a lot of their code in python. How easy and convenient is python for scientific computing? Does it have a library of algorithms that compares to matlab's? Is Python a scripting language or does it compile? Is it a great language for prototyping an algorithm? How long would it take me to learn enough of it to be productive provided I know C well and OO programming somewhat? Is it OO based?
Sorry for the condensed format of questions, but I'm very curious and was hoping a more experienced programmer could help me out. | Is Python appropriate for algorithms focused on scientific computing? | 0.024995 | 0 | 0 | 1,053 |
2,918,010 | 2010-05-27T01:53:00.000 | 5 | 1 | 0 | 0 | python,upload | 2,918,021 | 2 | false | 1 | 0 | No, that information isn't sent by the user, so it's not available on your end | 1 | 0 | 0 | Is it possible to get the full path of the file on the user's computer being uploaded to my site?
Using os.path.abspath(fileitem.filename) simply gets me the address of where my script is executing from on my shared hosting server.
FYI: fileitem = form['file'] and form = cgi.FieldStorage() | Get Path of Uploaded File using Python | 0.462117 | 0 | 0 | 1,903 |
2,918,362 | 2010-05-27T03:56:00.000 | 0 | 0 | 1 | 0 | python,newline | 71,482,534 | 18 | false | 0 | 0 | in order to suspport multiple operating systems use:
file.write(f'some strings and/or {variable}. {os.linesep}') | 1 | 365 | 0 | I want to append a newline to my string every time I call file.write(). What's the easiest way to do this in Python? | Writing string to a file on a new line every time | 0 | 0 | 0 | 984,695 |
2,918,445 | 2010-05-27T04:23:00.000 | 1 | 1 | 0 | 1 | python,user-interface,open-source,monodevelop,glade | 2,918,582 | 4 | false | 0 | 0 | To access really low end computers, and if you have no real graphics requirements, you could consider a text mode interface - curses/ncurses for one. | 1 | 3 | 0 | My student group and I are trying to continue working on a project we worked on this semester over the summer to become a professional, deployable app. We originally did it in Adobe AIR but it seems now that the computers this program will be running on will be very slow, maybe 600mhz and 128-256mb ram so flash just isn't going to cut it. It is basically a health diagnosis application that we will be shipping out to impoverished countries.
Now comes the real question. We are wondering what language to rebuild our application in. It has to have a good gui builder associated with it, like adobe flex/air gui builder or visual studio's gui builder but the application should run on linux primarily, and if it can run on windows thats just a plus. We are all students too without really any outside help so whatever we decide to do this in there must be ample documentation available when we hit problems.
Some things we have considered so far are using python and glade or c# and monodevelop, but again we really are not experts on any of this which is why I am asking for help as I would rather spend the time now choosing the right tools instead of wasting time down the line when we hit a roadblock.
Thanks in advance! | Making GUI applications on Linux/Windows. What languages/tools to use? | 0.049958 | 0 | 0 | 1,292 |
2,918,572 | 2010-05-27T04:55:00.000 | 7 | 0 | 1 | 0 | python,file-io | 2,918,597 | 3 | false | 0 | 0 | It's not that it adds a '\n' so much as that there's really one there. Use line = line.rstrip() to get the line sans newline (or something similar to it depending on exactly what you need).
Don't use the readline method for reading a file line by line. Just use for line in f:. Files already iterate over their lines. | 2 | 2 | 0 | I am reading one line at a time from a file, but at the end of each line it adds a '\n'.
Example:
The file has: 094 234 hii
but my input is: 094 234 hii\n
I want to read line by line but I don't need to keep the newlines...
My goal is to read a list from every line: I need ['094','234','hii'], not ['094','234','hii\n'].
Any advice? | problem with f.readline()? | 1 | 0 | 0 | 868 |
2,918,572 | 2010-05-27T04:55:00.000 | 5 | 0 | 1 | 0 | python,file-io | 2,918,599 | 3 | false | 0 | 0 | The \n is not added, it's part of the line that's being read. And when you do line.split() the traiing \n goes away anyway, so why are you worrying about it?! | 2 | 2 | 0 | I am reading one line at a time from a file, but at the end of each line it adds a '\n'.
Example:
The file has: 094 234 hii
but my input is: 094 234 hii\n
I want to read line by line but I don't need to keep the newlines...
My goal is to read a list from every line: I need ['094','234','hii'], not ['094','234','hii\n'].
Any advice? | problem with f.readline()? | 0.321513 | 0 | 0 | 868 |
2,920,619 | 2010-05-27T11:24:00.000 | 16 | 0 | 1 | 0 | python,list,definition,sequence,slice | 2,920,697 | 5 | true | 0 | 0 | list are more than plain arrays. You can initialize them without giving the number of items. You can append/push to them, you can remove/pop/del items from them, you can have lists of different types of objects (e.g., [1,'e', [3]]), you can have recursive lists... and you can slice lists, which means getting a new list with only a few of the items.
slice are an object type used "behind the scenes" to handle extended slicing in the a[start:stop:step] form, as help(slice) reveals.
"Sequence" is not an object, more like an informal interface some objects like list implement. | 3 | 35 | 0 | What are the differences between these built-in Python data types: list, sequence and slice? As I see it, all three essentially represent what C++ and Java call array. | Difference between list, sequence and slice in Python? | 1.2 | 0 | 0 | 36,747 |
2,920,619 | 2010-05-27T11:24:00.000 | 2 | 0 | 1 | 0 | python,list,definition,sequence,slice | 2,920,691 | 5 | false | 0 | 0 | Strictly speaking, a slice is a type which represents a range of indices, e.g. a start, stop, and a step. A slice isn't a container type at all. You can use a slice to index an list, resulting in a new list which is a copy of a sublist of the original list.
Lists differ from C++ arrays in that they're heterogenous; the elements are not required to be of the same type. And as MYYN has already pointed out, "sequence" isn't a Python type at all but rather a description of a variety of built-in types. | 3 | 35 | 0 | What are the differences between these built-in Python data types: list, sequence and slice? As I see it, all three essentially represent what C++ and Java call array. | Difference between list, sequence and slice in Python? | 0.07983 | 0 | 0 | 36,747 |
2,920,619 | 2010-05-27T11:24:00.000 | 75 | 0 | 1 | 0 | python,list,definition,sequence,slice | 2,921,465 | 5 | false | 0 | 0 | You're mixing very different things in your question, so I'll just answer a different question
You are now asking about one of the most important interface in Python: iterable - it's basically anything you can use like for elem in iterable.
iterable has three descendants: sequence, generator and mapping.
A sequence is a iterable with random access. You can ask for any item of the sequence without having to consume the items before it. With this property you can build slices, which give you more than one element at once. A slice can give you a subsequence: seq[from:until] and every nth item: seq[from:until:nth]. list, tuple and str all are sequences.
If the access is done via keys instead of integer positions, you have a mapping. dict is the basic mapping.
The most basic iterable is a generator. It supports no random access and therefore no slicing. You have to consume all items in the order they are given. Generator typically only create their items when you iterate over them. The common way to create generators are generator expressions. They look exactly like list comprehension, except with round brackets, for example (f(x) for x in y). Calling a function that uses the yield keyword returns a generator too.
The common adapter to all iterables is the iterator. iterators have the same interface as the most basic type they support, a generator. They are created explicitly by calling iter on a iterable and are used implicitly in all kinds of looping constructs. | 3 | 35 | 0 | What are the differences between these built-in Python data types: list, sequence and slice? As I see it, all three essentially represent what C++ and Java call array. | Difference between list, sequence and slice in Python? | 1 | 0 | 0 | 36,747 |
2,921,847 | 2010-05-27T14:10:00.000 | 22 | 0 | 1 | 0 | python,syntax,parameter-passing,iterable-unpacking,argument-unpacking | 2,921,872 | 5 | false | 0 | 0 | In a function call the single star turns a list into seperate arguments (e.g. zip(*x) is the same as zip(x1,x2,x3) if x=[x1,x2,x3]) and the double star turns a dictionary into seperate keyword arguments (e.g. f(**k) is the same as f(x=my_x, y=my_y) if k = {'x':my_x, 'y':my_y}.
In a function definition it's the other way around: the single star turns an arbitrary number of arguments into a list, and the double start turns an arbitrary number of keyword arguments into a dictionary. E.g. def foo(*x) means "foo takes an arbitrary number of arguments and they will be accessible through the list x (i.e. if the user calls foo(1,2,3), x will be [1,2,3])" and def bar(**k) means "bar takes an arbitrary number of keyword arguments and they will be accessible through the dictionary k (i.e. if the user calls bar(x=42, y=23), k will be {'x': 42, 'y': 23})". | 2 | 728 | 0 | What does the * operator mean in Python, such as in code like zip(*x) or f(**k)?
How is it handled internally in the interpreter?
Does it affect performance at all? Is it fast or slow?
When is it useful and when is it not?
Should it be used in a function declaration or in a call? | What does the star and doublestar operator mean in a function call? | 1 | 0 | 0 | 239,262 |
2,921,847 | 2010-05-27T14:10:00.000 | 52 | 0 | 1 | 0 | python,syntax,parameter-passing,iterable-unpacking,argument-unpacking | 2,923,051 | 5 | false | 0 | 0 | One small point: these are not operators. Operators are used in expressions to create new values from existing values (1+2 becomes 3, for example. The * and ** here are part of the syntax of function declarations and calls. | 2 | 728 | 0 | What does the * operator mean in Python, such as in code like zip(*x) or f(**k)?
How is it handled internally in the interpreter?
Does it affect performance at all? Is it fast or slow?
When is it useful and when is it not?
Should it be used in a function declaration or in a call? | What does the star and doublestar operator mean in a function call? | 1 | 0 | 0 | 239,262 |
2,922,548 | 2010-05-27T15:38:00.000 | 1 | 0 | 1 | 0 | python,sockets,file-descriptor | 2,922,605 | 2 | false | 0 | 0 | Why do you want to load this into memory using mmap? If you are on a unix variant, you can create a unix socket which is a file descriptor which can be used just like any other socket. A socket and a memory-mapped file are two distinct entities - it is probably not a good idea to try and mix them.
Perhaps it would be helpful to take a step back and discuss what you are trying to do at a higher level. | 1 | 0 | 0 | I'm trying to manually create the file descriptor associated with a socket in python and then loaded directly into memory with mmap. Create a file into memory with mmap is simple, but I can not find a way to associate the file with a socket.
Thanks for your responses.
The problem I have is I can not make more of a number of sockets for python (or operating system) I get the error: "[errno 24] Too many open files."
I think the error is because I can not create more file descriptors on disk, so I want to create them in memory. To avoid this limitation.
Any suggestions? | change file descriptor for socket in python | 0.099668 | 0 | 1 | 2,393 |
2,924,231 | 2010-05-27T19:28:00.000 | 0 | 0 | 0 | 0 | python,sqlite,browser | 2,979,467 | 8 | false | 0 | 0 | You question is a little broad. I'll try to cover as much as I can.
First, what I understood and my assumptions.
In your situation, the sqlite database is just a data store. Only one process (unless your application is multiprocess) will be accessing it so you won't need to worry about locking issues. The application doesn't need to communicate with other instances etc. over the network. It's a single desktop app. The platform is Windows.
Here are some thoughts that come to mind.
If you develop an application in Python (either web based or desktop), you will have to package it as a single executable and distribute it to your users. They might have to install the Python runtime as well as any extra modules that you might be using.
Guis are in my experience easier to develop using a standalone widget system than in a browser with Javascript. There are things like Pyjamas that make this better but it's still hard.
While it's not impossible to have local web applications running on each computer, your real benefits come if you centralise it. One place to update software. No need to "distribute" etc. This of course entails that you use a more powerful database system and you can actually manage multiple users. It will also require that you worry about browser specific quirks.
I'd go with a simple desktop app that uses a prepackaged toolkit (perhaps Tkinter which ships with Python). It's not the best of approaches but it will avoid problems for you. I'd also consider using a language that's more "first class" on windows like C# so that the runtimes and other things are already there. You requirement for a fancy GUI is secondary and I'd recommend that you get the functionality working fine before you focus on the bells and whistles.
Good luck. | 1 | 5 | 0 | I am in the planning stages of rewriting an Access db I wrote several years ago in a full fledged program. I have very slight experience coding, but not enough to call myself a programmer by far. I'll definitely be learning as I go, so I'd like to keep everything as simple as possible. I've decided on Python and SQLite for my program, but I need help on my next decision.
Here is my situation
1) It'll be run locally on each machine, all Windows computers
2) I would really like a nice looking GUI with colors, nice screens, menus, lists, etc,
3) I'm thinking about using a browser interface because (a) from what I've read, browser apps
can look really great, and (b) I understand there are lots of free tools to assist in setting up the GUI/GUI code with drag and drop tools, so that helps my "keep it simple" goal.
4) I want the program to be totally portable so it runs completely from one single folder on a user's PC, with no installation(s) needed for it to run
(If I did it as a browser app, isn't there the possibility that a user's browser settings could affect or break the app. How likely is this?)
For my situation, should/could I make it a browser app? What would be the pros and cons for my situation? | Python/Sqlite program, write as browser app or desktop app? | 0 | 1 | 0 | 5,638 |
2,924,736 | 2010-05-27T20:40:00.000 | 0 | 0 | 0 | 0 | python,cgi | 2,924,798 | 3 | false | 0 | 0 | I guess the IP should be static so do you really need to look it up more than once?
You need to specify the domain name so that the webserver knows which host configuration to use if you don't have a dedicated IP or your host is the default for that webserver | 1 | 0 | 0 | I have domain on a shared hosting provider. How do I find the direct IP address of my domain using Python?
Is it possible to post to a script on my domain using the IP address and not the website itself?
Thanks. | IP address of domain on shared host | 0 | 0 | 1 | 725 |
2,924,781 | 2010-05-27T20:46:00.000 | 2 | 0 | 0 | 0 | python,pyqt4,py2exe,qwebview | 2,925,711 | 1 | false | 1 | 1 | Only png support is native, jpg (and others) is supplied via plugins.
Don't recall the exact paths (and I don't know your platform) but search for the PyQt plugins folder and:
Copy the plugins folder to: $yourprogram/PyQt4/plugins (along with qt.conf)
Edit qt.conf, and change prefix to $yourprogram/PyQt4
You might also need to convince py2exe to also include this folder (verbatim). | 1 | 1 | 0 | I have an application that displays some HTML in a QWebview, which references images on the local file system. This works fine directly running the python. When compiling via py2exe, the images no longer load. Google doesn't seem to know the answer, any ideas? | Images not loading in QWebview in PyQt4 in py2exe | 0.379949 | 0 | 0 | 1,402 |
2,925,230 | 2010-05-27T21:48:00.000 | 1 | 0 | 1 | 0 | python,datetime,time,formatting | 2,925,269 | 8 | false | 1 | 0 | I know it's pretty cheap, but you could just discard the first character if it's a zero :) | 1 | 29 | 0 | I'm still a bit slow with Python, so I haven't got this figured out beyond what's obviously in the docs, etc.
I've worked with Django a bit, where they've added some datetime formatting options via template tags, but in regular python code how can I get the 12-hour hour without a leading zero?
Is there a straightforward way to do this? I'm looking at the 2.5 and 2.6 docs for "strftime()" and there doesn't seem to be a formatting option there for this case.
Should I be using something else?
Feel free to include any other time-formatting tips that aren't obvious from the docs. =) | Get "2:35pm" instead of "02:35PM" from Python date/time? | 0.024995 | 0 | 0 | 13,086 |
2,926,106 | 2010-05-28T01:17:00.000 | 1 | 0 | 0 | 0 | python,web-applications,temporary-files | 2,926,124 | 2 | false | 0 | 0 | Server-side web scripts have no access to the client other than through requests. If you can somehow break through the browser's protection settings to get JavaScript, Java, or Flash to read the contents of the client then you stand a fighting chance. But doing so will make many people angry and is generally considered a bad idea. | 1 | 0 | 0 | I wanted to know if there was a way I can get my python script located on a shared web hosting provider to read the contents of a folder on my desktop and list out the contents?
Can this be done using tempfiles? | Display folder contents on webpage using Python | 0.099668 | 0 | 0 | 536 |
2,926,220 | 2010-05-28T01:56:00.000 | 0 | 1 | 0 | 0 | python,streaming,webcam | 2,926,268 | 3 | false | 1 | 0 | Server-side web scripts have no access to the client other than through requests. You need to use JavaScript, Java, or Flash to access devices that the browser (and consequently user) allows them to. | 2 | 2 | 0 | Can a python script on my server access the webcam and audio input of a user as easily and as well as a Flash plugin can? | Python access webcam and audio input | 0 | 0 | 0 | 2,165 |
2,926,220 | 2010-05-28T01:56:00.000 | 2 | 1 | 0 | 0 | python,streaming,webcam | 2,926,270 | 3 | false | 1 | 0 | No: the "plugin" you mention runs in the user's browser, your server-side script (Python or otherwise) runs on the server, a completely different proposition. This relates to your other recent question about a server-side script accessing information on your desktop: your client machine tends to be very protected against possibly malicious server-side apps (never enough, but everybody keeps trying to make it more and more protected these days). | 2 | 2 | 0 | Can a python script on my server access the webcam and audio input of a user as easily and as well as a Flash plugin can? | Python access webcam and audio input | 0.132549 | 0 | 0 | 2,165 |
2,927,543 | 2010-05-28T08:22:00.000 | 1 | 1 | 0 | 0 | python,rss | 2,927,551 | 2 | false | 0 | 0 | Of course. BeautifulSoup, lxml, urllib2, urlgrabber. | 1 | 0 | 0 | I am trying to create a directory with news articles collected from an rss feed, meaning that whenever there is a link to an article within the rss feed, I would like for it to be downloaded in a directory with the title of the specific article as the filename as as a text file.
Is that something Python can help me do ?
Thank you for your help :-) | Downloading from links in an rss feed | 0.099668 | 0 | 1 | 442 |
2,930,211 | 2010-05-28T15:17:00.000 | 0 | 0 | 0 | 0 | c#,python,sockets | 2,965,960 | 2 | true | 1 | 0 | The easier way on my use case was send files using HTTP because with python i have additionaly running django. | 1 | 1 | 0 | i would like to know, what is the best way to send files between python and C# and vice versa.
I have my own protocol which work on socket level, and i can send string and numbers in both ways. Loops works too. With this i can send pretty much anything, like package of users id, if it is simple data. But soon i will start sending whole files, maybe xml or executables.
Simple server with files is no an option because i want sending files from client too.
I was thinking about serialization but i don't know it is the best solution, but if it is i will love some tips from stackoverflow community.
EDIT:
I added django to question and chose http. | Send files between python+django and C# | 1.2 | 0 | 1 | 347 |
2,932,007 | 2010-05-28T19:46:00.000 | 0 | 0 | 0 | 0 | python,linux,administration,func | 3,130,135 | 4 | false | 1 | 0 | It really depends what you're intending to do, as the question is a little vague. The other answers cover the tools available; choosing one over the other comes down to purpose.
Are you intending to manage servers, and services on those servers? If so, try Puppet, CFEngine, or some other tool for managing server configurations.
Or, more specifically, are you looking for a deployment/buildout tool that talks to servers? So that you can type in something along the lines of "mytool deploy myproject", and have your project propagate to all the servers? In which case, fabric would be the tool to use.
Generally a good configuration will consist of both anyway... but for what it's worth, from the sound of it (managing DHCP/network/etc.), Puppet's the way to go. | 1 | 0 | 0 | We're writing a web-based tool to configure our services provided by multiple servers. This includes interfaces configuration, dhcp configs etc. etc.
Having configs in database and views that generate proper output, how to send it/make it available for servers?
I'm thinking about sending it through scp and invoking reload command to services through ssh. I'm also thinking about using Func to do all the job, as this is Python tool and will seemingly integrate with python-based (django) config tool.
Any other proposals? | Methods of sending web-generated config files to servers and restarting services | 0 | 0 | 1 | 226 |
2,933,262 | 2010-05-29T00:28:00.000 | 0 | 0 | 0 | 0 | python,xml | 2,933,332 | 8 | false | 0 | 0 | If you're set on using minidom, just scan back in the file and remove the first line after writing all the XML you need. | 2 | 12 | 0 | when using Python's stock XML tools such as xml.dom.minidom for XML writing, a file would always start off like
<?xml version="1.0"?>
[...]
While this is perfectly legal XML code, and it's even recommended to use the header, I'd like to get rid of it as one of the programs I'm working with has problems here.
I can't seem to find the appropriate option in xml.dom.minidom, so I wondered if there are other packages which do allow to neglect the header.
Cheers,
Nico | How to write an XML file without header in Python? | 0 | 0 | 1 | 9,270 |
2,933,262 | 2010-05-29T00:28:00.000 | 0 | 0 | 0 | 0 | python,xml | 2,933,289 | 8 | false | 0 | 0 | Purists may not like to hear this, but I have found using an XML parser to generate XML to be overkill. Just generate it directly as strings. This also lets you generate files larger than you can keep in memory, which you can't do with DOM. Reading XML is another story. | 2 | 12 | 0 | when using Python's stock XML tools such as xml.dom.minidom for XML writing, a file would always start off like
<?xml version="1.0"?>
[...]
While this is perfectly legal XML code, and it's even recommended to use the header, I'd like to get rid of it as one of the programs I'm working with has problems here.
I can't seem to find the appropriate option in xml.dom.minidom, so I wondered if there are other packages which do allow to neglect the header.
Cheers,
Nico | How to write an XML file without header in Python? | 0 | 0 | 1 | 9,270 |
2,933,434 | 2010-05-29T01:49:00.000 | 1 | 1 | 1 | 0 | python,compiler-construction,project | 12,135,232 | 2 | false | 0 | 0 | Some other tools you might investigate to speed up python are
Cython, which requires type specification of all variables in the relevant method and then statically compiles the method
Numba, which requires LLVM but is JIT (methods must be decorated with argument types for compilation to occur). | 1 | 11 | 0 | I'm currently aware of the following Python JIT compilers: Psyco, PyPy and Unladen Swallow.
Basically, I'd like to ask for your personal experiences on the strengths and weaknesses of these compilers - and if there are any others worth looking into.
Thanks in advance,
Az | Strengths and weaknesses of JIT compilers for Python | 0.099668 | 0 | 0 | 5,073 |
2,933,601 | 2010-05-29T03:04:00.000 | 3 | 0 | 1 | 1 | python,terminal,stream | 2,933,610 | 2 | true | 0 | 0 | Open a pipe, then fork off a terminal running cat reading from the read end of the pipe, and write into the write end of the pipe. | 1 | 3 | 0 | I need output different information to different terminal instances instead of print them in same output stream, say std.err or std.out.
for example:
I have 5 kinds of information say A-E need to be displayed on different terminal windows on same desktop, looks like
[terminal 1] <- for displaying information A
[terminal 2] <- for displaying information B
[terminal 3] <- for displaying information C
[terminal 4] <- for displaying information D
[terminal 5] <- for displaying information E
I know I can output them into different files, then open terminals read the file in loop,
but what I want is python program can open terminal by program itself and print to them directly when it is needed.
Is it possible?
Thanks!
KC
[edit]
the best solution for this case is using SOCKET as the IPC I think if the resource is not a matter, it will come with best compatible capability - a server client mode.
and the pipe / subprocess will also be the useful solutions under same platform | how i can open different linux terminal to output differnt kinds of debug information in python? | 1.2 | 0 | 0 | 1,349 |
2,933,796 | 2010-05-29T04:25:00.000 | 2 | 0 | 0 | 0 | python,model-view-controller,sqlalchemy,dns,controllers | 2,934,084 | 1 | true | 1 | 0 | Controllers are meant to encapsulate features for your convienience. Not to bind your hands. If you want to join, simply join. Use the controller that you think is logically fittest to make the query. | 1 | 1 | 0 | When using SQL Alchemy for abstracting your data access layer and using controllers as the way to access objects from that abstraction layer, how should joins be handled?
So for example, say you have an Orders controller class that manages Order objects such that it provides getOrder, saveOrder, etc methods and likewise a similar controller for User objects.
First of all do you even need these controllers? Should you instead just treat SQL Alchemy as "the" thing for handling data access. Why bother with object oriented controller stuff there when you instead have a clean declarative way to obtain and persist objects without having to write SQL directly either.
Well one reason could be that perhaps you may want to replace SQL Alchemy with direct SQL or Storm or whatever else. So having controller classes there to act as an intermediate layer helps limit what would need to change then.
Anyway - back to the main question - so assuming you have these two controllers, now lets say you want the list of orders for a certain set of users meeting some criteria. How do you go about doing this? Generally you don't want the controllers crossing domains - the Orders controllers knows only about Orders and the User controller just about Users - they don't mess with each other. You also don't want to go fetch all the Users that match and then feed a big list of user ids to the Orders controller to go find the matching Orders.
What's needed is a join. Here's where I'm stuck - that seems to mean either the controllers must cross domains or perhaps they should be done away with altogether and you simply do the join via SQL Alchemy directly and get the resulting User and / or Order objects as needed. Thoughts? | SQL Alchemy MVC and cross controller joins | 1.2 | 1 | 0 | 430 |
2,934,435 | 2010-05-29T09:02:00.000 | 1 | 0 | 0 | 1 | python,macos,wxpython,pyobjc | 2,958,571 | 2 | true | 0 | 1 | Can you create a hidden window that is offscreen somewhere? It is a hack, but I remember having to do a lot of hacks to make my wxPython-based application work correctly on Mac OS X.
Note:You'll have to disable the close button and set up that hidden window so that it doesn't show up in the Window menu.
Aside:Have you considered factoring out your GUI portion of your Python application and using PyObjC on Mac OS X? You'll get more native behaviours... | 1 | 5 | 0 | I am writing a wxPython application that remains open after closing all of its windows - so you can still drag & drop new files onto the OSX dock icon (I do this with myApp.SetExitOnFrameDelete(False)).
Unfortunately if I close all the windows, the OSX menubar will only contain a "Help" menu. I would like to add at least a File/Open menu item, or just keep the menubar of the main window. Is this somehow possible in wxPython?
In fact, I would be happy with a non-wxPython hack as well (for example, setting the menu in pyobjc, but running the rest of the GUI in wxPython). wxPython development in OSX is such a hack anyway ;)
UPDATE: I managed to solve this problem using the tip from Lyndsey Ferguson. Here's what I have done:
On startup I create a window which I show and hide immediately. I set its position to (-10000,-10000) so that it does not flicker on the screen (aargh, what a dirty hack!)
I create an empty EVT_CLOSE event handler in that window so that it cannot be closed.
It seems that destroying a window resets the OSX menu, but hiding does not... So when the last window is closed, I need to show and hide this window again (hiding is necessary so that the user cannot switch to this window using the Window menu or Cmd-`)
Yeah, this is really ugly... I will be very grateful if someone comes up with a prettier solution.
UPDATE 2: Actually it can be solved in a much easier way: if we do not close the last window, only hide it. And ensure that it does not respond to menu events anymore. | How to change the OSX menubar in wxPython without any opened window? | 1.2 | 0 | 0 | 1,471 |
2,935,631 | 2010-05-29T15:35:00.000 | 1 | 0 | 0 | 1 | python,google-app-engine,task-queue | 2,935,659 | 2 | true | 1 | 0 | The development server won't run tasks automatically, you have to set them off yourself.
It's a design feature, so you can see what happens when you run them, instead of them running at any point.
Essentially, there's nothing wrong with your application, it's a feature of development server. | 1 | 1 | 0 | I was playing with Goole App Engine Task Queue API to learn how to use it. But I couldn't make it trigger locally. My application is working like a charm when I upload to Google servers. But it doesn't trigger locally. All I see from the admin is the list of the tasks. But when their ETA comes, they just pass it. It's like they runs but they fails and waiting for the retries. But I can't see these events on command line.
When I try to click "Run" on admin panel, it runs successfuly and I can see these requests from the command line. I'm using App Engine SDK 1.3.4 on Linux with google-app-engine-django. I'm trying to find the problem from 3 hours now and I couldn't find it. It's also very hard to debug GAE applications. Because debug messages do not appear on console screen.
Thanks. | Task Queue stopped working | 1.2 | 0 | 0 | 391 |
2,935,836 | 2010-05-29T16:46:00.000 | 1 | 0 | 1 | 1 | python,multithreading,command-line,ipc,interprocess | 2,935,858 | 4 | false | 0 | 0 | Perhaps try using sockets for communication? | 2 | 14 | 0 | I'd like to prevent multiple instances of the same long-running python command-line script from running at the same time, and I'd like the new instance to be able to send data to the original instance before the new instance commits suicide. How can I do this in a cross-platform way?
Specifically, I'd like to enable the following behavior:
"foo.py" is launched from the command line, and it will stay running for a long time-- days or weeks until the machine is rebooted or the parent process kills it.
every few minutes the same script is launched again, but with different command-line parameters
when launched, the script should see if any other instances are running.
if other instances are running, then instance #2 should send its command-line parameters to instance #1, and then instance #2 should exit.
instance #1, if it receives command-line parameters from another script, should spin up a new thread and (using the command-line parameters sent in the step above) start performing the work that instance #2 was going to perform.
So I'm looking for two things: how can a python program know another instance of itself is running, and then how can one python command-line program communicate with another?
Making this more complicated, the same script needs to run on both Windows and Linux, so ideally the solution would use only the Python standard library and not any OS-specific calls. Although if I need to have a Windows codepath and an *nix codepath (and a big if statement in my code to choose one or the other), that's OK if a "same code" solution isn't possible.
I realize I could probably work out a file-based approach (e.g. instance #1 watches a directory for changes and each instance drops a file into that directory when it wants to do work) but I'm a little concerned about cleaning up those files after a non-graceful machine shutdown. I'd ideally be able to use an in-memory solution. But again I'm flexible, if a persistent-file-based approach is the only way to do it, I'm open to that option.
More details: I'm trying to do this because our servers are using a monitoring tool which supports running python scripts to collect monitoring data (e.g. results of a database query or web service call) which the monitoring tool then indexes for later use. Some of these scripts are very expensive to start up but cheap to run after startup (e.g. making a DB connection vs. running a query). So we've chosen to keep them running in an infinite loop until the parent process kills them.
This works great, but on larger servers 100 instances of the same script may be running, even if they're only gathering data every 20 minutes each. This wreaks havoc with RAM, DB connection limits, etc. We want to switch from 100 processes with 1 thread to one process with 100 threads, each executing the work that, previously, one script was doing.
But changing how the scripts are invoked by the monitoring tool is not possible. We need to keep invocation the same (launch a process with different command-line parameters) but but change the scripts to recognize that another one is active, and have the "new" script send its work instructions (from the command line params) over to the "old" script.
BTW, this is not something I want to do on a one-script basis. Instead, I want to package this behavior into a library which many script authors can leverage-- my goal is to enable script authors to write simple, single-threaded scripts which are unaware of multi-instance issues, and to handle the multi-threading and single-instancing under the covers. | can a python script know that another instance of the same script is running... and then talk to it? | 0.049958 | 0 | 0 | 3,867 |
2,935,836 | 2010-05-29T16:46:00.000 | 0 | 0 | 1 | 1 | python,multithreading,command-line,ipc,interprocess | 2,936,096 | 4 | false | 0 | 0 | Sounds like your best bet is sticking with a pid file but have it not only contain the process Id - have it also include the port number that the prior instance is listening on. So when starting up check for the pid file and if present see if a process with that Id is running - if so send your data to it and quit otherwise overwrite the pid file with the current process's info. | 2 | 14 | 0 | I'd like to prevent multiple instances of the same long-running python command-line script from running at the same time, and I'd like the new instance to be able to send data to the original instance before the new instance commits suicide. How can I do this in a cross-platform way?
Specifically, I'd like to enable the following behavior:
"foo.py" is launched from the command line, and it will stay running for a long time-- days or weeks until the machine is rebooted or the parent process kills it.
every few minutes the same script is launched again, but with different command-line parameters
when launched, the script should see if any other instances are running.
if other instances are running, then instance #2 should send its command-line parameters to instance #1, and then instance #2 should exit.
instance #1, if it receives command-line parameters from another script, should spin up a new thread and (using the command-line parameters sent in the step above) start performing the work that instance #2 was going to perform.
So I'm looking for two things: how can a python program know another instance of itself is running, and then how can one python command-line program communicate with another?
Making this more complicated, the same script needs to run on both Windows and Linux, so ideally the solution would use only the Python standard library and not any OS-specific calls. Although if I need to have a Windows codepath and an *nix codepath (and a big if statement in my code to choose one or the other), that's OK if a "same code" solution isn't possible.
I realize I could probably work out a file-based approach (e.g. instance #1 watches a directory for changes and each instance drops a file into that directory when it wants to do work) but I'm a little concerned about cleaning up those files after a non-graceful machine shutdown. I'd ideally be able to use an in-memory solution. But again I'm flexible, if a persistent-file-based approach is the only way to do it, I'm open to that option.
More details: I'm trying to do this because our servers are using a monitoring tool which supports running python scripts to collect monitoring data (e.g. results of a database query or web service call) which the monitoring tool then indexes for later use. Some of these scripts are very expensive to start up but cheap to run after startup (e.g. making a DB connection vs. running a query). So we've chosen to keep them running in an infinite loop until the parent process kills them.
This works great, but on larger servers 100 instances of the same script may be running, even if they're only gathering data every 20 minutes each. This wreaks havoc with RAM, DB connection limits, etc. We want to switch from 100 processes with 1 thread to one process with 100 threads, each executing the work that, previously, one script was doing.
But changing how the scripts are invoked by the monitoring tool is not possible. We need to keep invocation the same (launch a process with different command-line parameters) but but change the scripts to recognize that another one is active, and have the "new" script send its work instructions (from the command line params) over to the "old" script.
BTW, this is not something I want to do on a one-script basis. Instead, I want to package this behavior into a library which many script authors can leverage-- my goal is to enable script authors to write simple, single-threaded scripts which are unaware of multi-instance issues, and to handle the multi-threading and single-instancing under the covers. | can a python script know that another instance of the same script is running... and then talk to it? | 0 | 0 | 0 | 3,867 |
2,936,384 | 2010-05-29T19:48:00.000 | 0 | 0 | 0 | 0 | python,web-applications,printing | 2,936,475 | 2 | false | 1 | 0 | If your Python webapp is running inside a browser on the client machine, I don't see any other way than manually for the user.
Some workarounds you might want to investigate:
if you web app is installed on the client machine, you will be able to connect directly to the printer, as you have access to the underlying OS system.
you could potentially create a plugin that can be installed on the browser that does this for him, but I have no clue as how this works technically.
what is it that you want to print ? You could generate a pdf that contains everything that the user needs to print, in one go ? | 1 | 0 | 0 | Is it possible for my python web app to provide an option the for user to automatically send jobs to the locally connected printer? Or will the user always have to use the browser to manually print out everything. | python web script send job to printer | 0 | 0 | 1 | 1,545 |
2,937,114 | 2010-05-30T00:43:00.000 | -6 | 0 | 1 | 0 | python,if-statement,sequence,sequences | 2,937,150 | 7 | false | 0 | 0 | Why are you doing this? The normal way here is to require a certain type of thing (A sequence or a number or a file-like object, etc.) and then use it without checking anything. In Python, we don't typically use classes to carry semantic information but simply use the methods defined (this is called "duck typing"). We also prefer APIs where we know exactly what to expect; use keyword arguments, preprocessing, or defining another function if you want to change how a function works. | 1 | 82 | 0 | In python is there an easy way to tell if something is not a sequence? I tried to just do:
if x is not sequence but python did not like that | Python: check if an object is a sequence | -1 | 0 | 0 | 47,990 |
2,937,619 | 2010-05-30T05:06:00.000 | 2 | 0 | 0 | 0 | python,sql,r,large-files,large-data-volumes | 2,942,419 | 8 | false | 0 | 0 | When you say "accumulating" then solution (2) looks most suitable to problem.
After initial load up to database you only update database with new files (daily, weekly? depends how often you need this).
In cases (1) and (3) you need to process files each time (what was stated earlier as most time/resources-consuming), unless you find a way to stored results and update them with new files.
You could use R to process files from csv to, for example, SQLite database. | 4 | 32 | 0 | I have large amounts of data (a few terabytes) and accumulating... They are contained in many tab-delimited flat text files (each about 30MB). Most of the task involves reading the data and aggregating (summing/averaging + additional transformations) over observations/rows based on a series of predicate statements, and then saving the output as text, HDF5, or SQLite files, etc. I normally use R for such tasks but I fear this may be a bit large. Some candidate solutions are to
write the whole thing in C (or
Fortran)
import the files (tables) into a
relational database directly and
then pull off chunks in R or Python
(some of the transformations are not
amenable for pure SQL solutions)
write the whole thing in Python
Would (3) be a bad idea? I know you can wrap C routines in Python but in this case since there isn't anything computationally prohibitive (e.g., optimization routines that require many iterative calculations), I think I/O may be as much of a bottleneck as the computation itself. Do you have any recommendations on further considerations or suggestions? Thanks
Edit Thanks for your responses. There seems to be conflicting opinions about Hadoop, but in any case I don't have access to a cluster (though I can use several unnetworked machines)... | large amount of data in many text files - how to process? | 0.049958 | 1 | 0 | 5,360 |
2,937,619 | 2010-05-30T05:06:00.000 | 4 | 0 | 0 | 0 | python,sql,r,large-files,large-data-volumes | 2,937,664 | 8 | false | 0 | 0 | With terabytes, you will want to parallelize your reads over many disks anyway; so might as well go straight into Hadoop.
Use Pig or Hive to query the data; both have extensive support for user-defined transformations, so you should be able to implement what you need to do using custom code. | 4 | 32 | 0 | I have large amounts of data (a few terabytes) and accumulating... They are contained in many tab-delimited flat text files (each about 30MB). Most of the task involves reading the data and aggregating (summing/averaging + additional transformations) over observations/rows based on a series of predicate statements, and then saving the output as text, HDF5, or SQLite files, etc. I normally use R for such tasks but I fear this may be a bit large. Some candidate solutions are to
write the whole thing in C (or
Fortran)
import the files (tables) into a
relational database directly and
then pull off chunks in R or Python
(some of the transformations are not
amenable for pure SQL solutions)
write the whole thing in Python
Would (3) be a bad idea? I know you can wrap C routines in Python but in this case since there isn't anything computationally prohibitive (e.g., optimization routines that require many iterative calculations), I think I/O may be as much of a bottleneck as the computation itself. Do you have any recommendations on further considerations or suggestions? Thanks
Edit Thanks for your responses. There seems to be conflicting opinions about Hadoop, but in any case I don't have access to a cluster (though I can use several unnetworked machines)... | large amount of data in many text files - how to process? | 0.099668 | 1 | 0 | 5,360 |
2,937,619 | 2010-05-30T05:06:00.000 | 1 | 0 | 0 | 0 | python,sql,r,large-files,large-data-volumes | 2,937,660 | 8 | false | 0 | 0 | Yes. You are right! I/O would cost most of your processing time. I don't suggest you to use distributed systems, like hadoop, for this task.
Your task could be done in a modest workstation. I am not an Python expert, I think it has support for asynchronous programming. In F#/.Net, the platform has well support for that. I was once doing an image processing job, loading 20K images on disk and transform them into feature vectors only costs several minutes in parallel.
all in all, load and process your data in parallel and save the result in memory (if small), in database (if big). | 4 | 32 | 0 | I have large amounts of data (a few terabytes) and accumulating... They are contained in many tab-delimited flat text files (each about 30MB). Most of the task involves reading the data and aggregating (summing/averaging + additional transformations) over observations/rows based on a series of predicate statements, and then saving the output as text, HDF5, or SQLite files, etc. I normally use R for such tasks but I fear this may be a bit large. Some candidate solutions are to
write the whole thing in C (or
Fortran)
import the files (tables) into a
relational database directly and
then pull off chunks in R or Python
(some of the transformations are not
amenable for pure SQL solutions)
write the whole thing in Python
Would (3) be a bad idea? I know you can wrap C routines in Python but in this case since there isn't anything computationally prohibitive (e.g., optimization routines that require many iterative calculations), I think I/O may be as much of a bottleneck as the computation itself. Do you have any recommendations on further considerations or suggestions? Thanks
Edit Thanks for your responses. There seems to be conflicting opinions about Hadoop, but in any case I don't have access to a cluster (though I can use several unnetworked machines)... | large amount of data in many text files - how to process? | 0.024995 | 1 | 0 | 5,360 |
2,937,619 | 2010-05-30T05:06:00.000 | 14 | 0 | 0 | 0 | python,sql,r,large-files,large-data-volumes | 2,937,630 | 8 | true | 0 | 0 | (3) is not necessarily a bad idea -- Python makes it easy to process "CSV" file (and despite the C standing for Comma, tab as a separator is just as easy to handle) and of course gets just about as much bandwidth in I/O ops as any other language. As for other recommendations, numpy, besides fast computation (which you may not need as per your statements) provides very handy, flexible multi-dimensional arrays, which may be quite handy for your tasks; and the standard library module multiprocessing lets you exploit multiple cores for any task that's easy to parallelize (important since just about every machine these days has multi-cores;-). | 4 | 32 | 0 | I have large amounts of data (a few terabytes) and accumulating... They are contained in many tab-delimited flat text files (each about 30MB). Most of the task involves reading the data and aggregating (summing/averaging + additional transformations) over observations/rows based on a series of predicate statements, and then saving the output as text, HDF5, or SQLite files, etc. I normally use R for such tasks but I fear this may be a bit large. Some candidate solutions are to
write the whole thing in C (or
Fortran)
import the files (tables) into a
relational database directly and
then pull off chunks in R or Python
(some of the transformations are not
amenable for pure SQL solutions)
write the whole thing in Python
Would (3) be a bad idea? I know you can wrap C routines in Python but in this case since there isn't anything computationally prohibitive (e.g., optimization routines that require many iterative calculations), I think I/O may be as much of a bottleneck as the computation itself. Do you have any recommendations on further considerations or suggestions? Thanks
Edit Thanks for your responses. There seems to be conflicting opinions about Hadoop, but in any case I don't have access to a cluster (though I can use several unnetworked machines)... | large amount of data in many text files - how to process? | 1.2 | 1 | 0 | 5,360 |
2,938,405 | 2010-05-30T11:29:00.000 | 5 | 0 | 1 | 0 | python,multithreading | 2,938,465 | 3 | false | 0 | 0 | Your question cannot be answered in a general way, as good usage of threading always depends on concrete problem to be solved. You also do not tell us, which Python version you are using, so I assume you use the "default" CPython and not IronPython or something like that. To give you some hints and ideas to further think about your problem:
Why do you need so much treads? Your machine will probably not be able to run them in parallel anyway.
Have a look at Stackless Python. Don't know the current status of the project, but I think it was designed for that kind of problems.
The global interpreter lock prevents pure Python code from really running in parallel. But C methods can be run in parallel, so in real life it's sometimes hard to guess, how Python will behave regarding parallelization.
Python has many good libraries. Have a look whether one of them already has a solution for your design problem. If your problem is network related, have a look at Twisted for example. | 1 | 4 | 0 | I'm quite new to threading in Python and have a couple of beginner questions.
When starting more than say fifty threads using the Python threading module I start getting MemoryError. The threads themselves are very slim and not very memory hungry, so it seems like it is the overhead of the threading that causes the memory issues.
Is there something I can do to increase the memory capacity or otherwise make Python allow for a larger number of threads?
What is the maximum number of threads you've been able to run in your Python code using the threading module? Did you do any tricks to achieve that number?
Are there any other caveats to be aware of when using the threading module? | Caveats to be aware of when using threading in Python? | 0.321513 | 0 | 0 | 1,096 |
2,938,757 | 2010-05-30T13:14:00.000 | 1 | 1 | 1 | 0 | python,encryption | 2,939,776 | 2 | false | 0 | 0 | You can read the complete file into a string, encrypt it, write the encrypted string in a new file. If the file is too large, you can read in chunks.
Every time you .read from a file, you get a string (in Python < 3.0). | 1 | 6 | 0 | Is there a way to encrypt files (.zip, .doc, .exe, ... any type of file) with Python?
I've looked at a bunch of crypto libraries for Python including pycrypto and ezpycrypto but as far as I see they only offer string encryption. | File encryption with Python | 0.099668 | 0 | 0 | 972 |
2,938,874 | 2010-05-30T13:51:00.000 | 0 | 0 | 0 | 0 | python,grid,resize,pyqt4,qwebview | 6,977,293 | 2 | false | 0 | 1 | in the dialog class's resizeEvent, one that extends QDialog, call webView->setGeometry, and this->resize, this->update.
hint: check if size changed via the QResizeEvent *ptr | 1 | 0 | 0 | I have a QWebview in a grid layout, along with other widgets. When the user resizes the window, the QWebview doesn't resize, but the other widgets do. How can I make the QWebview resize correctly? | PyQT4 QWebView not resizing correctly | 0 | 0 | 0 | 1,113 |
2,939,224 | 2010-05-30T15:30:00.000 | 4 | 0 | 0 | 0 | python,tkinter,media,pyaudio,audio-player | 2,939,414 | 3 | false | 0 | 1 | Probably you have to use threads for that. You have to play your audio file in a different thread than the gui mainloop so that the GUI keeps responding user input.
IMHO, wxpython is not so complicated and has some utility functions that would help to do what you want. Check the wxpython demo, you have several examples there. | 1 | 0 | 0 | I'm developing a media player. Right now it's a simple window with a button to load .wav files. The problem is I would like to implement a pause button now. But, when playing a audio file the GUI isn't accessible again (no buttons can be pushed) till the file is done playing. How can I make the GUI dynamic while an audio file is playing?
I'm using PyAudio, and their implementation doesn't allow this. | Python/Tkinter Audio Player | 0.26052 | 0 | 0 | 3,328 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.