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
3,881,364
2010-10-07T11:56:00.000
1
0
0
0
python,sqlalchemy,entity
3,896,280
1
true
1
0
You can expunge it from session before modifying object, then this changes won't be accounted on next commits unless you add the object back to session. Just call session.expunge(obj).
1
0
0
i just want to use an entity modify it to show something,but don't want to change to the db, but after i use it ,and in some other place do the session.commit() it will add this entity to db,i don't want this happen, any one could help me?
use sqlalchemy entity isolately
1.2
1
0
85
3,881,534
2010-10-07T12:19:00.000
18
0
1
1
python,vim,virtualenv,macvim
3,881,570
6
false
0
0
Activate your virtualenv before starting vim. You will automatically get the corresponding interpreter instance.
1
18
0
I use vim for coding and for python coding in particular. Often I want to execute the current buffer with python interpreter. (for example to run unittests), usually I do this with :!python % <Enter> This scenatio will work works fine with global python, but I want to run virtualenv python instead. How do I enable virtualenv within vim? Is it possible to switch virtualenv on the runtime? I'm using macvim
Set python virtualenv in vim
1
0
0
20,646
3,881,951
2010-10-07T13:10:00.000
0
0
0
0
python
3,882,193
2
false
0
0
The IP addresses are assigned to your VPSes, no possibility to change them on the fly. You have to open a SSH tunnel to or install a proxy on your VPSes. I think a SSH tunnel would be the best way how to do it, and then use it as SOCKS5 proxy from Python.
1
1
0
I am running my code on multiple VPSes (with more than one IP, which are set up as aliases to the network interfaces) and I am trying to figure out a way such that my code acquires the IP addresses from the network interfaces on the fly and bind to it. Any ideas on how to do it in python without adding a 3rd party library ? Edit I know about socket.gethostbyaddr(socket.gethostname()) and about the 3rd party package netifaces, but I am looking for something more elegant from the standard library ... and parsing the output of the ifconfig command is not something elegant :)
figuring out how to get all of the public ips of a machine
0
0
1
118
3,882,249
2010-10-07T13:45:00.000
0
0
0
0
java,c++,python,powerpoint,google-docs
3,899,697
3
true
1
0
Now i found a solution to showing .ppt file on my website without using the flash the solution is: just convert the .ppt file to .pdf files using any language or using software(e.g. open office) and then use Imagemagick to convert that .pdf into image and show to your web page once again thanks to you all for answering my question.
1
2
0
I want to show .ppt (PowerPoint) files uploaded by my user on my website. I could do this by converting them into Flash files, then showing the Flash files on the web page. But I don't want to use Flash to do this. I want to show it, like google docs shows, without using Flash. I've already solved the problem for .pdf files by converting them into images using ImageMagick, but now I have trouble with .ppt files.
How google docs shows my .PPT files without using a flash viewer?
1.2
0
1
1,773
3,882,750
2010-10-07T14:35:00.000
0
1
1
0
python,ironpython,pickle
3,927,390
2
false
0
0
It will work because when you unpickle objects during load() it will use the current definitions of whatever classes you have defined now, not back when the objects were pickled. IronPython is simply Python with the standard library implemented in C# so that everything emits IL. Both the CPython and the IronPython pickle modules have the same functionality, except one is implemented in C and the other in C#.
2
5
0
I was wondering whether objects serialized using CPython's cPickle are readable by using IronPython's cPickle; the objects in question do not require any modules outside of the built-ins that both Cpython and IronPython include. Thank you!
compatibility between CPython and IronPython cPickle
0
0
0
871
3,882,750
2010-10-07T14:35:00.000
2
1
1
0
python,ironpython,pickle
3,883,735
2
false
0
0
If you use the default protocol (0) which is text based, then things should work. I'm not sure what will happen if you use a higher protocol. It's very easy to test this ...
2
5
0
I was wondering whether objects serialized using CPython's cPickle are readable by using IronPython's cPickle; the objects in question do not require any modules outside of the built-ins that both Cpython and IronPython include. Thank you!
compatibility between CPython and IronPython cPickle
0.197375
0
0
871
3,882,921
2010-10-07T14:53:00.000
4
0
1
0
python,nlp,stemming,stop-words
3,883,529
2
false
0
0
If for some reason you don't want to use NLTK, you can try PyStemmer. For stop words just download a list (google it) and filter them out.
1
4
0
I have a somewhat large document and want to do stop-word elimination and stemming on the words of this document with Python. Does anyone know an of the shelf package for these? If not a code which is fast enough for large documents is also welcome. Thanks
Stop-word elimination and stemmer in python
0.379949
0
0
2,262
3,883,484
2010-10-07T15:56:00.000
9
1
1
0
python,code-coverage,reverse-engineering,code-analysis
3,886,403
3
true
0
0
What you want isn't "test coverage", it is the transitive closure of "can call" from the root of the computation. (In threaded applications, you have to include "can fork"). You want to designate some small set (perhaps only 1) of functions that make up the entry points of your application, and want to trace through all possible callees (conditional or unconditional) of that small set. This is the set of functions you must have. Python makes this very hard in general (IIRC, I'm not a deep Python expert) because of dynamic dispatch and especially due to "eval". Reasoning about what function can get called can be pretty tricky for a static analyzers applied to highly dynamic languages. One might use test coverage as a way to seed the "can call" relation with specific "did call" facts; that could catch a lot of dynamic dispatches (dependent on your test suite coverage). Then the result you want is the transitive closure of "can or did" call. This can still be erroneous, but is likely to be less so. Once you get a set of "necessary" functions, the next problem will be removing the unnecessary functions from the source files you have. If the number of files you start with is large, the manual effort to remove the dead stuff may be pretty high. Worse, you're likely to revise your application, and then the answer as to what to keep changes. So for every change (release), you need to reliably recompute this answer. My company builds a tool that does this analysis for Java packages (with appropriate caveats regarding dynamic loads and reflection): the input is a set of Java files and (as above) a designated set of root functions. The tool computes the call graph, and also finds all dead member variables and produces two outputs: a) the list of purportedly dead methods and members, and b) a revised set of files with all the "dead" stuff removed. If you believe a), then you use b). If you think a) is wrong, then you add elements listed in a) to the set of roots and repeat the analysis until you think a) is right. To do this, you need a static analysis tool that parse Java, compute the call graph, and then revise the code modules to remove the dead entries. The basic idea applies to any language. You'd need a similar tool for Python, I'd expect. Maybe you can stick to just dropping files that are completely unused, although that may still be a lot of work.
3
8
0
My project targets a low-cost and low-resource embedded device. I am dependent on a relatively large and sprawling Python code base, of which my use of its APIs is quite specific. I am keen to prune the code of this library back to its bare minimum, by executing my test suite within a coverage tools like Ned Batchelder's coverage or figleaf, then scripting removal of unused code within the various modules/files. This will help not only with understanding the libraries' internals, but also make writing any patches easier. Ned actually refers to the use of coverage tools to "reverse engineer" complex code in one of his online talks. My question to the SO community is whether people have experience of using coverage tools in this way that they wouldn't mind sharing? What are the pitfalls if any? Is the coverage tool a good choice? Or would I be better off investing my time with figleaf? The end-game is to be able to automatically generate a new source tree for the library, based on the original tree, but only including the code actually used when I run nosetests. If anyone has developed a tool that does a similar job for their Python applications and libraries, it would be terrific to get a baseline from which to start development. Hopefully my description makes sense to readers...
Using Python code coverage tool for understanding and pruning back source code of a large library
1.2
0
0
2,137
3,883,484
2010-10-07T15:56:00.000
0
1
1
0
python,code-coverage,reverse-engineering,code-analysis
3,883,765
3
false
0
0
I haven't used coverage for pruning out, but it seems like it should do well. I've used the combination of nosetests + coverage, and it worked better for me than figleaf. In particular, I found the html report from nosetests+coverage to be helpful -- this should be helpful to you in understanding where the unused portions of the library are.
3
8
0
My project targets a low-cost and low-resource embedded device. I am dependent on a relatively large and sprawling Python code base, of which my use of its APIs is quite specific. I am keen to prune the code of this library back to its bare minimum, by executing my test suite within a coverage tools like Ned Batchelder's coverage or figleaf, then scripting removal of unused code within the various modules/files. This will help not only with understanding the libraries' internals, but also make writing any patches easier. Ned actually refers to the use of coverage tools to "reverse engineer" complex code in one of his online talks. My question to the SO community is whether people have experience of using coverage tools in this way that they wouldn't mind sharing? What are the pitfalls if any? Is the coverage tool a good choice? Or would I be better off investing my time with figleaf? The end-game is to be able to automatically generate a new source tree for the library, based on the original tree, but only including the code actually used when I run nosetests. If anyone has developed a tool that does a similar job for their Python applications and libraries, it would be terrific to get a baseline from which to start development. Hopefully my description makes sense to readers...
Using Python code coverage tool for understanding and pruning back source code of a large library
0
0
0
2,137
3,883,484
2010-10-07T15:56:00.000
2
1
1
0
python,code-coverage,reverse-engineering,code-analysis
3,890,093
3
false
0
0
As others have pointed out, coverage can tell you what code has been executed. The trick for you is to be sure that your test suite truly exercises the code fully. The failure case here is over-pruning because your tests skipped some code that will really be needed in production. Be sure to get the latest version of coverage.py (v3.4): it adds a new feature to indicate files that are never executed at all. BTW:: for a first cut prune, Python provides a neat trick: remove all the .pyc files in your source tree, then run your tests. Files that still have no .pyc file were clearly not executed!
3
8
0
My project targets a low-cost and low-resource embedded device. I am dependent on a relatively large and sprawling Python code base, of which my use of its APIs is quite specific. I am keen to prune the code of this library back to its bare minimum, by executing my test suite within a coverage tools like Ned Batchelder's coverage or figleaf, then scripting removal of unused code within the various modules/files. This will help not only with understanding the libraries' internals, but also make writing any patches easier. Ned actually refers to the use of coverage tools to "reverse engineer" complex code in one of his online talks. My question to the SO community is whether people have experience of using coverage tools in this way that they wouldn't mind sharing? What are the pitfalls if any? Is the coverage tool a good choice? Or would I be better off investing my time with figleaf? The end-game is to be able to automatically generate a new source tree for the library, based on the original tree, but only including the code actually used when I run nosetests. If anyone has developed a tool that does a similar job for their Python applications and libraries, it would be terrific to get a baseline from which to start development. Hopefully my description makes sense to readers...
Using Python code coverage tool for understanding and pruning back source code of a large library
0.132549
0
0
2,137
3,883,497
2010-10-07T15:57:00.000
18
0
0
0
python,django
3,883,556
3
true
1
0
Just run two instances of ./manage.py runserver. You can set a port by simply specifying it directly: ./manage.py runserver 8002 to listen on port 8002. Edit I don't really understand why you want to do this. If you want two servers serving different parts of your site, then you have in effect two sites, which will need two separate settings.py and urls.py files. You'd then run one instance of runserver with each, passing the settings flag appropriately: ./manage.py runserver 8002 --settings=app1.settings
2
8
0
Could someone tell me how I can run Django on two ports simultaneously? The default Django configuration only listens on port 8000. I'd like to run another instance on port xxxx as well. I'd like to redirect all requests to this second port to a particular app in my Django application. I need to accomplish this with the default Django installation and not by using a webserver like nginx, Apache, etc. Thank you Let's say I two applications in my Django application. Now i don't mean two separate Django applications but the separate folders inside the 'app' directory. Let's call this app1 and app2 I want all requests on port 8000 to go to app1 and all requests on port XXXX to go to app2 HTH.
Run Django on multiple ports
1.2
0
0
14,240
3,883,497
2010-10-07T15:57:00.000
2
0
0
0
python,django
3,883,557
3
false
1
0
The built-in web-server is intended for development only, so you should really be using apache or similar in an situation where you need to run on multiple ports. On the other hand you should be able to start up multiple servers just by starting multiple instances of runserver. As long as you are using a separate database server I don't think that will have any extra problems.
2
8
0
Could someone tell me how I can run Django on two ports simultaneously? The default Django configuration only listens on port 8000. I'd like to run another instance on port xxxx as well. I'd like to redirect all requests to this second port to a particular app in my Django application. I need to accomplish this with the default Django installation and not by using a webserver like nginx, Apache, etc. Thank you Let's say I two applications in my Django application. Now i don't mean two separate Django applications but the separate folders inside the 'app' directory. Let's call this app1 and app2 I want all requests on port 8000 to go to app1 and all requests on port XXXX to go to app2 HTH.
Run Django on multiple ports
0.132549
0
0
14,240
3,883,619
2010-10-07T16:12:00.000
0
0
1
0
python,django,shell,ipython
34,309,424
5
false
1
0
The easiest solution I've found is combination of shell_plus and iPython which automatically reloads functions. pip install ipython pip install django-extensions add 'django_extensions' to your INSTALLED_APPS python manage.py shell_plus
1
6
0
I work in the django IPython-shell, which can be started with manage.py shell. When i load an extern function in the shell for testing, everything is alright. But when i make changes to the function, the shell still has the old version of the function. Even if i make a new import. Does anyone know how to reload the actual version of the function? Thanks in regards! Edit: I use windows - if that makes a difference.
django, python: reload function in shell
0
0
0
8,233
3,883,724
2010-10-07T16:26:00.000
1
1
0
0
python,c,embedded-language
3,884,055
1
false
0
1
This may not be the answer you want, but there are ways of working with C and Python other than embedding an interpreter inside a C application. Namely, why don't you do the opposite? Create C libraries for Python? You can control the general flow of your application in Python, which is much more comfortable, and call C code whenever you see fit. Again, I'm not really addressing your actual question, so feel free to ignore me.
1
0
0
Due to refactoring/reworking on a controller I've had to embed a Python Interpreter inside a C application. I can now call python functions and pass/get Objects into Python fine. The python code is a controller for a robot (currently simulated), this now needs make use of some C code for comparisons I'm making. Previously the Python code created objects, read sensors, ran control code and wrote the outputs to motors. All of this except the control code now needs to be done in C. The problem I have is that Objects which are created in an init function (in python) which, when I come to run the control code no longer exist. What is the best way to solve this? My idea was to return the controllers from the init function and store references to them in the C, passing the reference to the controller each time it is called. Thanks for any help.
Maintaining a Python Object when embedding in C
0.197375
0
0
102
3,884,405
2010-10-07T17:56:00.000
2
0
1
0
c#,python,vb.net,user-interface
3,884,537
4
false
0
0
For programming on Windows you want to go with .NET and probably WPF for the presentation layer if you can wrap your head around MVVM as it gives you much more scope for delivering flexible UIs than forms. For cross platform utility - probably python, but I'm not sure I'd want it to be my principal development tool (if I'm focusing on Windows applications).
3
0
0
I am hired by my local company here which makes small accounting/billing/payroll softwares to manage its clients' companies. Most of them use windows platform and the softwares themselves will not be too complex ones. I want to ask which language should i opt for? Python, C#, VB.net or something else which will make the GUI programming task easier. thanks in advance.
Windows platform programming
0.099668
0
0
147
3,884,405
2010-10-07T17:56:00.000
2
0
1
0
c#,python,vb.net,user-interface
3,885,769
4
false
0
0
The advice to build upon what you already know is very good advice. As you are thinking of Python, I feel i should warn you off Iron Python. I found it very very slow and WPF confused the heck out of me. The designer is nice. The error messages you get when importing the wrong namespaces are cryptic and comfusing (Example - "Error: expected X got X"). Qt, PyQt and Python appears to be acceptably quick (Python is no speed demon), well documented and stable. It will adopt the local styling, so it looks native XP or Win 7 with no changes. Fair warning about Python. It boasts of being "batteries included". This is great until you find there are 4 different modules that might do what you want, and no decent documentation for any of them, to help you choose the most suitable.
3
0
0
I am hired by my local company here which makes small accounting/billing/payroll softwares to manage its clients' companies. Most of them use windows platform and the softwares themselves will not be too complex ones. I want to ask which language should i opt for? Python, C#, VB.net or something else which will make the GUI programming task easier. thanks in advance.
Windows platform programming
0.099668
0
0
147
3,884,405
2010-10-07T17:56:00.000
0
0
1
0
c#,python,vb.net,user-interface
3,884,449
4
false
0
0
My personal preference is WPF/C#. I say go with the latest technology (whichever YOU find easiest), it will be good for your career.
3
0
0
I am hired by my local company here which makes small accounting/billing/payroll softwares to manage its clients' companies. Most of them use windows platform and the softwares themselves will not be too complex ones. I want to ask which language should i opt for? Python, C#, VB.net or something else which will make the GUI programming task easier. thanks in advance.
Windows platform programming
0
0
0
147
3,884,795
2010-10-07T18:44:00.000
2
0
1
0
python,pdf,gis,geospatial
3,885,385
3
true
0
0
One option is to use GDAL... The latest version (i.e. the current svn trunk, not any released version) of gdal should support geoPDF's. You'll need to compile it with the option --with-poppler=yes and have the poppler pdf library installed. (Compiling gdal can be a bit of a pain, just to warn you ahead of time...) Gdal's python bindings are painful, but they generally work. From there, you should be able to easily use GDAL to convert your geopdf's to georeferenced jpegs. If you're not already familiar with GDAL, though, this may be more trouble than it's worth. The georeferenceing information in a geoPDF can probably be extracted in other ways... Hope that helps a bit, anyway...
1
2
0
I want to organize lots of geoPDF files so they can easily viewed overlayed onto Google Maps and Google Earth. My 1st step, I think, is to convert the geoPDF to a jpg type image which then needs matching lat,long information. Is there python code to parse a geoPDF file to get the projection and image data? A geoPDF2KML tool?
Is there python code to parse a geoPDF file to get the projection and image data? a geoPDF2KML tool?
1.2
0
0
2,683
3,884,881
2010-10-07T18:53:00.000
0
0
1
1
python,windows-xp
3,884,931
3
false
0
0
You need to map it as a drive.
1
2
0
How can I open a Python interpreter at a specific network path in Windows? In the Explorer address bar the path is in UNC form: \\myhost\myshare\.... I can't work out how to change to this directory from the Windows command line, nor in what format I could pass it as an argument to os.chdir. I'm running Python 2.5 on Windows XP. IDLE is installed. Thanks!
How can I open a Python shell at a network path in Windows?
0
0
0
2,258
3,885,160
2010-10-07T19:24:00.000
0
0
0
1
python,linux,networking,ip-address
3,885,255
2
false
0
0
If the default gateway for the system is reliable, then grab that from the output from route -n the line that contains " UG " (note the spaces) will also contain the IP of the gateway and interface name of the active interface.
1
1
0
On my linux machine, 1 of 3 network interfaces may be actually connected to the internet. I need to get the IP address of the currently connected interface, keeping in mind that my other 2 interfaces may be assigned IP addresses, just not be connected. I can just ping a website through each of my interfaces to determine which one has connectivity, but I'd like to get this faster than waiting for a ping time out. And I'd like to not have to rely on an external website being up. Update: All my interfaces may have ip addresses and gateways. This is for an embedded device. So we allow the user to choose between say eth0 and eth1. But if there's no connection on the interface that the user tells us to use, we fall back to say eth2 which (in theory) will always work. So what I need to do is first check if the user's selection is connected and if so return that IP. Otherwise I need to get the ip of eth2. I can get the IPs of the interfaces just fine, it's just determining which one is actually connected.
Determine IP address of CONNECTED interface (linux) in python
0
0
1
2,443
3,885,489
2010-10-07T20:09:00.000
5
1
0
0
python,unit-testing,testing
3,885,518
5
false
0
0
Or would such an approach be antithetical to unit testing's underlying philosophy? Yep...if it is a unit test, it should be able to run on its own. Anytime I have found someone wanting to create dependencies on tests was due to the code being structured in a poor manner. I am not saying this is the instance in your case but it can often be a sign of code smell.
4
6
0
I'm wondering if there is a test framework that allows for tests to be declared as being dependent on other tests. This would imply that they should not be run, or that their results should not be prominently displayed, if the tests that they depend on do not pass. The point of such a setup would be to allow the root cause to be more readily determined in a situation where there are many test failures. As a bonus, it would be great if there some way to use an object created with one test as a fixture for other tests. Is this feature set provided by any of the Python testing frameworks? Or would such an approach be antithetical to unit testing's underlying philosophy?
Test framework allowing tests to depend on other tests
0.197375
0
0
1,809
3,885,489
2010-10-07T20:09:00.000
0
1
0
0
python,unit-testing,testing
3,891,628
5
false
0
0
It looks like what you need is not to prevent the execution of your dependent tests but to report the results of your unit test in a more structured way that allows you to identify when an error in a test cascades onto other failed tests.
4
6
0
I'm wondering if there is a test framework that allows for tests to be declared as being dependent on other tests. This would imply that they should not be run, or that their results should not be prominently displayed, if the tests that they depend on do not pass. The point of such a setup would be to allow the root cause to be more readily determined in a situation where there are many test failures. As a bonus, it would be great if there some way to use an object created with one test as a fixture for other tests. Is this feature set provided by any of the Python testing frameworks? Or would such an approach be antithetical to unit testing's underlying philosophy?
Test framework allowing tests to depend on other tests
0
0
0
1,809
3,885,489
2010-10-07T20:09:00.000
1
1
0
0
python,unit-testing,testing
3,895,868
5
false
0
0
This seems to be a recurring question - e.g. #3396055 It most probably isn't a unit-test, because they should be fast (and independent). So running them all isn't a big drag. I can see where this might help in short-circuiting integration/regression runs to save time. If this is a major need for you, I'd tag the setup tests with [Core] or some such attribute. I then proceed to write a build script which has two tasks Taskn : run all tests in X,Y,Z dlls marked with tag [Core] Taskn+1 depends on Taskn: run all tests in X,Y,Z dlls excluding those marked with tag [Core] (Taskn+1 shouldn't run if Taskn didn't succeed.) It isn't a perfect solution - e.g. it would just bail out if any one [Core] test failed. But I guess you should be fixing the Core ones instead of proceeding with Non-Core tests.
4
6
0
I'm wondering if there is a test framework that allows for tests to be declared as being dependent on other tests. This would imply that they should not be run, or that their results should not be prominently displayed, if the tests that they depend on do not pass. The point of such a setup would be to allow the root cause to be more readily determined in a situation where there are many test failures. As a bonus, it would be great if there some way to use an object created with one test as a fixture for other tests. Is this feature set provided by any of the Python testing frameworks? Or would such an approach be antithetical to unit testing's underlying philosophy?
Test framework allowing tests to depend on other tests
0.039979
0
0
1,809
3,885,489
2010-10-07T20:09:00.000
0
1
0
0
python,unit-testing,testing
3,897,462
5
false
0
0
The test runners py.test, Nosetests and unit2/unittest2 all support the notion of "exiting after the first failure". py.test more generally allows to specify "--maxfail=NUM" to stop running and reporting after NUM failures. This may already help your case especially since maintaining and updating dependencies for tests may not be that interesting a task.
4
6
0
I'm wondering if there is a test framework that allows for tests to be declared as being dependent on other tests. This would imply that they should not be run, or that their results should not be prominently displayed, if the tests that they depend on do not pass. The point of such a setup would be to allow the root cause to be more readily determined in a situation where there are many test failures. As a bonus, it would be great if there some way to use an object created with one test as a fixture for other tests. Is this feature set provided by any of the Python testing frameworks? Or would such an approach be antithetical to unit testing's underlying philosophy?
Test framework allowing tests to depend on other tests
0
0
0
1,809
3,885,519
2010-10-07T20:13:00.000
0
0
0
0
python,web-services,usb
3,885,544
2
false
0
0
This doesn't seem much different then serving files from a local hard drive. You could map the thumbdrive to always be something not currently used on your machine (like U:).
1
0
0
Using just python, is it possible to possible to use a USB flash drive to serve files locally to a browser, and save information off the online web? Ideally I would only need python. Where would I start?
Is it possible to use a USB flash drive to serve files locally to a browser?
0
0
1
195
3,886,281
2010-10-07T22:19:00.000
3
0
1
0
python,image,image-processing,numpy
25,062,330
3
false
0
0
Quick addition: for displaying with matplotlib, if you want the image to appear "raster", i.e., pixelized without smoothing, then you should include the option interpolation='nearest' in the call to imshow.
1
23
1
I've got a numpy array in Python and I'd like to display it on-screen as a raster image. What is the simplest way to do this? It doesn't need to be particularly fancy or have a nice interface, all I need to do is to display the contents of the array as a greyscale raster image. I'm trying to transition some of my IDL code to Python with NumPy and am basically looking for a replacement for the tv and tvscl commands in IDL.
Display array as raster image in python
0.197375
0
0
41,992
3,886,402
2010-10-07T22:38:00.000
7
0
1
0
python,floating-point,decimal
66,605,212
36
false
0
0
To make it work with both positive and negative numbers: try abs(x)%1. For negative numbers, without with abs, it will go wrong. 5.55 % 1 output 0.5499999999999998 -5.55 % 1 output 0.4500000000000002
1
164
0
How do I get the numbers after a decimal point? For example, if I have 5.55, how do i get .55?
How to get numbers after decimal point?
1
0
0
285,621
3,886,500
2010-10-07T22:56:00.000
0
0
0
0
python,multithreading,pyqt,copy-paste
3,886,510
1
false
0
1
In Qt you would overload the OnClose method for the widget/frame or hook the lastwindowsdclosed signal to do whatever you need to shut down the app - don't know if it's diiferent from python
1
0
0
I have a programs that runs several threads (on a while loop until Ctrl C is pressed). The app also has a GUI that I developed in PyQt. However, I am facing the following problem: If I press Ctrl C on the console, and then close the GUI, the program exits fine. However, if I close the GUI first, the other threads won't stop and the program keeps running after Ctrl C. Anyone knows how I could address this problem?
PyQT4 and Ctrl C
0
0
0
722
3,887,017
2010-10-08T01:09:00.000
0
0
0
0
python,django-models,input,field
3,887,176
1
false
1
0
How about creating a separate model for each type of field you want to support, and then another model consisting of a list of (table_name, entry_id) pairs, which could be customized to use any combination of fields?
1
0
0
This is my first post here, and I'd like to describe what I want to do as specific as possible. I'd like to make a model that is 'selectable.' for example, class SimpleModel(models.Model): property = models.CharField(max_length=255) value = GeneralField() GeneralField can be "CharField", "URLField", "TextField" so that user can select appropriate input type for specific property. I'm kinda thinking of this similar to Wordpress's custom_field. My initial thought is making TextField and tweak input interface depends on user's selection, but it's a bit tricky and if it involves file uploading functionality, it's gonna be complicated. of course, I googled a lot. If you have any thoughts on this, please give me a tip :) thanx in advance
Letting users to choose what type of content they want to input
0
0
0
63
3,887,675
2010-10-08T04:20:00.000
1
0
0
0
python,openerp
10,221,855
4
false
1
0
related fields leads the control to another table the parent table wil have a onetomany relation with the child table and the child table have a manytoone relation towards the parent table. eg: the account.invoice to account.invoice.line with the following field 'invoice_line': fields.one2many('account.invoice.line', 'invoice_id', 'Invoice Lines', readonly=True, states={'draft':[('readonly',False)]}), and account.invoice.line relates to account.invoice with the following code in reverse. 'invoice_id': fields.many2one('account.invoice', 'Invoice Reference', ondelete='cascade', select=True),
1
10
0
Can someone explain to me something about related fields. For example - How it was used How it can be helped For which kind of scenario I should use fields.related If anybody can provide a small example for real use of fields.related I would appreciate it.
What is the use of related fields in OpenERP?
0.049958
0
0
11,804
3,888,125
2010-10-08T06:17:00.000
0
0
0
0
python,qr-code
5,047,781
5
false
0
1
pyqrnative is working pretty well for me. I wish I could find some documentation in English for it. Would like to know the relationship between data content size and the first "typeNumber" argument.
1
5
0
I am looking for qrcode generator for python window version. Can anyone help me to find out. I didn't get anywhere. Please help me. Thanks, manu
qrcode generator using python for windows
0
0
0
8,188
3,888,812
2010-10-08T08:20:00.000
0
0
0
1
python,urllib2,urllib,buffering,urlopen
3,888,827
2
true
0
0
A quick hack that has occurred to me is to use urllib.urlopen() with threading.Timer() to emulate timeout. But that's only quick and dirty hack.
1
1
0
I have client for web interface to long running process. I'd like to have output from that process to be displayed as it comes. Works great with urllib.urlopen(), but it doesn't have timeout parameter. On the other hand with urllib2.urlopen() the output is buffered. Is there a easy way to disable that buffer?
unbuffered urllib2.urlopen
1.2
0
1
1,600
3,889,769
2010-10-08T10:47:00.000
6
0
0
0
python,django,http-headers,httprequest
46,259,055
10
false
1
0
request.META.get('HTTP_AUTHORIZATION') /python3.6/site-packages/rest_framework/authentication.py you can get that from this file though...
1
131
0
I need to get all the Django request headers. From what I've read, Django simply dumps everything into the request.META variable along with a lot of other data. What would be the best way to get all the headers that the client sent to my Django application? I'm going use these to build a httplib request.
How can I get all the request headers in Django?
1
0
0
150,515
3,890,271
2010-10-08T12:03:00.000
1
0
0
0
python,webcam
3,890,377
2
false
0
0
You could do it with some kind of java applet or flash/silverlight application, just look at sites like "chat roulette"
1
0
0
Is it possible to stream my webcam form my local machine that's connected to the internet to show up on my website without using any media server or something similar?
How to stream my webcam through my site?
0.099668
0
1
807
3,890,321
2010-10-08T12:11:00.000
8
0
1
0
python,grammar
3,890,344
2
true
0
0
Grammars are generally of the same form: Backus-Naur Form (BNF) is typical. Lexer/parsers can take very different forms. The lexer breaks up the input file into tokens. The parser uses the grammar to see if the stream of tokens is "valid" according to its rules. Usually the outcome is an abstract syntax tree (AST) that can then be used to generate whatever you want, such as byte code or assembly.
1
4
0
I wonder how is generated the grammar of the Python language and how it is understood by the interpreter. In python, the file graminit.c seems to implement the grammar, but i don't clearly understand it. More broadly, what are the different ways to generate a grammar and are there differences between how the grammar is implemented in languages such as Perl, Python or Lua.
How is generated the python grammar and how the interpreter understand it
1.2
0
0
841
3,890,390
2010-10-08T12:22:00.000
7
0
1
0
javascript,python,sockets,encoding
3,890,407
2
false
1
0
JSON is definitely the way to go. It has a very small overhead and is capable of storing almost any kind of data. I am not a python expert, but i am sure that there is some kind of en/decoder available.
1
1
0
OK so im using websockets to let javascript talk to python and that works very well BUT the data i need to send often has several parts like an array, (username,time,text) but how could i send it ? I originally though to encode each one in base64 or urlencode then use a character like | which those encoding methods will never use and then split the information. Unfortunately i cant find a method which both python and javascript can both do. So the question, is there a encoding method which bath can do OR is there a different better way i can send the data because i havent really done anything like this before. (I have but AJAX requests and i send that data URL encoded). Also im not sending miles of text, about 100bytes at a time if that. thankyou ! edit Most comments point to JSON,so, Whats the best convert to use for javascript because javascript stupidly cant convert string to JSON,or the other way round. Finished Well jaascript does have a native way to convert javascript to string, its just hidden form the world. JSON.stringify(obj, [replacer], [space]) to convert it to a string and JSON.parse(string, [reviver]) to convert it back
Python to javascript communication
1
0
1
1,908
3,891,180
2010-10-08T13:48:00.000
1
0
0
0
python,random,numpy,shuffle,sampling
18,177,268
6
false
0
0
people using numpy version 1.7 or later there can also use the builtin function numpy.random.choice
1
13
1
I'm writing some modelling routines in NumPy that need to select cells randomly from a NumPy array and do some processing on them. All cells must be selected without replacement (as in, once a cell has been selected it can't be selected again, but all cells must be selected by the end). I'm transitioning from IDL where I can find a nice way to do this, but I assume that NumPy has a nice way to do this too. What would you suggest? Update: I should have stated that I'm trying to do this on 2D arrays, and therefore get a set of 2D indices back.
Select cells randomly from NumPy array - without replacement
0.033321
0
0
15,426
3,891,645
2010-10-08T14:40:00.000
0
0
0
0
python,algorithm,cluster-analysis,classification,nearest-neighbor
3,893,461
3
false
0
0
If your number of clusters is fixed and you only want to maximize the number of points that are in these clusters then I think a greedy solution would be good : find the rectangle that can contains the maximum number of points, remove these points, find the next rectangle ... So how to find the rectangle of maximum area A (in fact each rectangle will have this area) that contains the maximum number of points ? A rectangle is not really common for euclidean distance, before trying to solve this, could you precise if you really need rectangle or just some king of limit on the cluster size ? Would a circle/ellipse work ? EDIT : greedy will not work (see comment below) and it really need to be rectangles...
1
4
1
I've been tasked to find N clusters containing the most points for a certain data set given that the clusters are bounded by a certain size. Currently, I am attempting to do this by plugging in my data into a kd-tree, iterating over the data and finding its nearest neighbor, and then merging the points if the cluster they make does not exceed a limit. I'm not sure this approach will give me a global solution so I'm looking for ways to tweak it. If you can tell me what type of problem this would go under, that'd be great too.
Clustering problem
0
0
0
1,423
3,893,885
2010-10-08T19:56:00.000
2
0
1
0
python
3,893,929
9
false
0
0
If there is no way to tell where the string will be (first half, second half, etc) then there is really no optimized way to do the search other than the builtin "find" function. You could reduce the I/O time and memory consumption by not reading the file all in one shot, but at 4kb blocks (which is usually the size of an hard disk block). This will not make the search faster, unless the string is in the first part of the file, but in all case will reduce memory consumption which might be a good idea if the file is huge.
1
41
0
I need to search a pretty large text file for a particular string. Its a build log with about 5000 lines of text. Whats the best way to go about doing that? Using regex shouldn't cause any problems should it? I'll go ahead and read blocks of lines, and use the simple find.
Cheap way to search a large text file for a string
0.044415
0
0
134,926
3,894,278
2010-10-08T21:00:00.000
0
0
0
0
python,twisted
8,505,450
3
false
1
0
use defer.inlineCallbacks can make your codes easiler to read.. and it somehow like corountine style: you neither block the call nor use chain of callbacks to build the whole logic. It is intuitive.
2
11
0
Is there any reason to use one over the other? Do they have the same performance?
Twisted Deferred.addCallBack() vs. yield and @inlineDeferred
0
0
0
5,275
3,894,278
2010-10-08T21:00:00.000
2
0
0
0
python,twisted
3,894,412
3
false
1
0
The differences should really be subtle. If this code really does run that often that it matters, perhaps you should look into your application design. Otherwise, take the variant which is more easy to read, you will have to make heads and tails out of it a couple of months or years down the road. EDIT: If you really want to know, here is how you find out (it could, after all, be implementation specific to your python version): run both version in a tight loop and measure the time. Increase loop count until the time difference between the versions is far greater than the time variance of the same version across multiple runs. Repeat after changing python version, OS etc.
2
11
0
Is there any reason to use one over the other? Do they have the same performance?
Twisted Deferred.addCallBack() vs. yield and @inlineDeferred
0.132549
0
0
5,275
3,895,359
2010-10-09T01:48:00.000
0
1
1
0
python,design-patterns,global-variables,class-design
3,895,385
2
false
0
0
There is no problem with using properties on classes. Classes are just objects, too. In your case, with this little information available, I would go for a class property, too, because not creating dependencies ist great and will be one worry less sometimes later.
1
4
0
Little question concerning app architecture: I have a python script, running as a daemon. Inside i have many objects, all inheriting from one class (let's name it 'entity') I have also one main object, let it be 'topsys' Entities are identified by pair (id, type (= class, roughly)), and they are connected in many wicked ways. They are also created and deleted all the time, and they are need to access other entities. So, i need a kind of storage, basically dictionary of dictionaries (one for each type), holding all entities. And the question is, what is better: attach this dictionary to 'topsys' as a object property or to class entity, as a property of the class? I would opt for the second (so entities does not need to know of existence of 'topsys'), but i am not feeling good about using properties directly in classes. Or maybe there is another way?
python global object cache
0
0
0
3,257
3,896,087
2010-10-09T15:11:00.000
4
0
0
0
python,blender,panda3d
3,896,157
2
true
1
0
From a python automation point of view, blender itself is written largely in python, and the source is available which allows a level of automation not possible if you can't change the source. To me, having the source available in that situation is more of a benefit than the price tag. If you do go with blender, definitely grab the 2.5 beta. They made some huge UI and scripting improvements. In my opinion, most of the complaints about it being difficult to learn compared to commercial packages are no longer valid for 2.5, especially if you don't have the mental burden of already having learned another software's interface.
1
2
0
I am getting started with the development of 3d environments for using in panda3d. As I am new to this, I need to choose a modelling software to create basic geometries, etc. Therefore, which one is better suited for automation through python? 3DS Max or Blender3D? I would like to automate generating basic geometries, the export process and some basic animations. Blender has the benefit of being free, but my office will provide me the licenses for 3DS if I request, so that is not a problem.
Blender3d vs 3DS max; which one is better suited for automation in python?
1.2
0
0
1,647
3,896,313
2010-10-09T16:04:00.000
1
0
0
1
c++,python,scripting,lua
3,897,041
4
false
0
1
Guile is easy to embed and extend, and scheme if powerfull programming language. You can compile libguile and add it to the repository in lib directory or add source for guile and compile it when user compile the project. But I don't try to use guile on Windows.
3
3
0
I need a simple interpreter which will do execution (evaluation) of simple expressions/statements and also call functions from main C++ applications. At the moment I do not need scripting of the application, but it may be useful later. It should also be strait-forward for other team members to pull my application from Source Repository and to build it, without having to install additional application, libraries, etc. Searching reveled options like: Python (via Boost and / or Python API), Lua, Guile, TinyScheme. I am the closest to Python, but using Boost, building Python library, complicated task of interfacing main application with Python makes this choice an overkill, maybe I am wrong. There should be a simple solution for this request, what are your experiences and suggestions?
Simple interpreter to embed and extend inside an C++ Windows application
0.049958
0
0
739
3,896,313
2010-10-09T16:04:00.000
4
0
0
1
c++,python,scripting,lua
3,897,270
4
true
0
1
Two great options you've already listed are Python and Lua. Here are some of the tradeoffs for your consideration: Python A much more complete and powerful language (IMHO!) with libraries for anything and tons of support and communities everywhere you look. Syntax is not entirely C-like Although Python wasn't designed specifically for embedding (it's much more often used as a standalone language extended by code in C/C++), it's tot really hard to embed. The official docs contain some examples, and following Boost's examples shouldn't be much harder. Lua Designed from bottom up for embedding, so it should be the simplest one to embed. Syntax more C-like than Python's If you foresee a definite future need for scripting, building in a scripting engine early is a good idea as it may open some interesting possibilities for you as you go on developing the program. Both options listed above are good ones, you should have no problems embedding any of them without much effort.
3
3
0
I need a simple interpreter which will do execution (evaluation) of simple expressions/statements and also call functions from main C++ applications. At the moment I do not need scripting of the application, but it may be useful later. It should also be strait-forward for other team members to pull my application from Source Repository and to build it, without having to install additional application, libraries, etc. Searching reveled options like: Python (via Boost and / or Python API), Lua, Guile, TinyScheme. I am the closest to Python, but using Boost, building Python library, complicated task of interfacing main application with Python makes this choice an overkill, maybe I am wrong. There should be a simple solution for this request, what are your experiences and suggestions?
Simple interpreter to embed and extend inside an C++ Windows application
1.2
0
0
739
3,896,313
2010-10-09T16:04:00.000
2
0
0
1
c++,python,scripting,lua
3,898,118
4
false
0
1
No matter which scripting language you choose (and I would probably vote for Python), you might consider using SWIG (www.swig.org) to ease the burden of interfacing to C++. While normally used to build C++ extensions for python (or ruby, lua, guile, any many others), it can be used to aid in embedding too. You had mentioned boost::python, which is certainly a full featured option, and allows for a somewhat closer Python/C++ integration (especially where virtual functions are involved). However, in my experience, SWIG is a lot easier to integrate, works with scads of scripting languages, and for python, is natively supported by Python's distutils.
3
3
0
I need a simple interpreter which will do execution (evaluation) of simple expressions/statements and also call functions from main C++ applications. At the moment I do not need scripting of the application, but it may be useful later. It should also be strait-forward for other team members to pull my application from Source Repository and to build it, without having to install additional application, libraries, etc. Searching reveled options like: Python (via Boost and / or Python API), Lua, Guile, TinyScheme. I am the closest to Python, but using Boost, building Python library, complicated task of interfacing main application with Python makes this choice an overkill, maybe I am wrong. There should be a simple solution for this request, what are your experiences and suggestions?
Simple interpreter to embed and extend inside an C++ Windows application
0.099668
0
0
739
3,896,741
2010-10-09T09:24:00.000
0
0
0
0
python,django,cloud
3,896,820
3
false
1
0
If you're going to use a web framework on the server, it makes sense to use an HTTP-based protocol. The downside is that only the client can initiate a connection (e.g., the client needs to first ask for the "dump" file), but a simple GET request will suffice (remember, the server can send anything in the HTTP response, including your XML file). Regarding encryption, it's best to use an existing protocol like HTTPS. There are well-vetted libraries that will correctly establish a secure connection between your client and the server. Overall, I'm advocating the highest-level protocols that are appropriate for your application. HTTP(S) goes hand-in-hand with your web-based architecture, so make use of it.
2
1
0
For my final year project I plan to code a cloud in Python. The client will be written in Java by the other member of my team. The client will have a tabbed interface and it will provide a text editor, a media player, a couple of small Java based games and a maybe a few more services. The server will work like this: 1) Validate the user. 2) Send a file, called "dump" to the user. Dump will contain all the file names and file types that the user created by himself or the files which the user can read/write. This info will be fetched from the database. 3) The tabs in the client will display the file types associated with the tab application. e.g the media tab will only select and show the media files from the dump readable by user. The text editor tab will show only the txt files from the dump readable by the user. 4) A request to open the file will send the file back to client, which the associated application will open. 5) All the changes made to the files and all the actions (overwriting, saving, deleting etc.) will be sent back to the server along with the new object. Something similar will be done to the newly created objects. My Questions are: What are the best approaches for the communication between the client and the server. For the dump I plan to use some sort of encrypted XML file. For the other way round, I don't have a clue :/. For easy integration with the database, I was planning to use Django (which I started few days back). How can I send my requests from the client to the server (without Django I'd use SQL queries) and the files from the server to the client? Maybe GET and POST will work for the former problem? Any other suggestions?
How to do cloud computing with Python and Java? Final Year project
0
0
0
2,332
3,896,741
2010-10-09T09:24:00.000
0
0
0
0
python,django,cloud
3,896,834
3
false
1
0
Stick to Django. It's really productive. I would use JSON instead of XML. More convenient. import json. This should help you in communicating between client-server. Also cloud computing is just a recent word that's just thrown around for (client+server+some services). Oh by the way all that you want to do can be completely done in Django itself. No need to go to JAVA. Django is Cool :)
2
1
0
For my final year project I plan to code a cloud in Python. The client will be written in Java by the other member of my team. The client will have a tabbed interface and it will provide a text editor, a media player, a couple of small Java based games and a maybe a few more services. The server will work like this: 1) Validate the user. 2) Send a file, called "dump" to the user. Dump will contain all the file names and file types that the user created by himself or the files which the user can read/write. This info will be fetched from the database. 3) The tabs in the client will display the file types associated with the tab application. e.g the media tab will only select and show the media files from the dump readable by user. The text editor tab will show only the txt files from the dump readable by the user. 4) A request to open the file will send the file back to client, which the associated application will open. 5) All the changes made to the files and all the actions (overwriting, saving, deleting etc.) will be sent back to the server along with the new object. Something similar will be done to the newly created objects. My Questions are: What are the best approaches for the communication between the client and the server. For the dump I plan to use some sort of encrypted XML file. For the other way round, I don't have a clue :/. For easy integration with the database, I was planning to use Django (which I started few days back). How can I send my requests from the client to the server (without Django I'd use SQL queries) and the files from the server to the client? Maybe GET and POST will work for the former problem? Any other suggestions?
How to do cloud computing with Python and Java? Final Year project
0
0
0
2,332
3,897,040
2010-10-09T17:07:00.000
1
0
1
0
python,dictionary,iteration,average
3,897,064
3
false
0
0
Inherit from dict and calculate the average value each time __setitem__ is called. Since you can store the previous average in your dictionary class and only average this and the new value that is added, that should be pretty fast - the first time a new item is added, the average value is simply that of this value.
1
4
0
I'm trying to find the fastest/most efficient way to extract the average value from a dict. The task I'm working on requires that it do this thousands of times, so simply iterating over all the values in the dict each time to find the average would be entirely inefficient. Hundreds and hundreds of new key,value pairs get added to the dict and we need to find the average value each time this occurs. We also need to find the new average value each time a value gets updated, which occurs thousands of times. Thanks in advance--this is such an awesome place.
Python - Fastest way to find the average value over entire dict each time it gets modified?
0.066568
0
0
4,313
3,897,101
2010-10-09T17:20:00.000
3
0
1
1
python,linux,user-interface
3,897,118
2
true
0
0
There are numerous decent GUI toolkits, the most popular being PyQt, PyGTK, wxPython and Tkinter. Personally, I prefer Qt, but that's really subjective.
2
0
0
I am new to GUI development. What is the best GUI development package for python on linux (ubuntu being more specific)?
GUI development package
1.2
0
0
238
3,897,101
2010-10-09T17:20:00.000
1
0
1
1
python,linux,user-interface
3,897,128
2
false
0
0
This is much more a matter of personal taste. I use GTK+ with Glade.
2
0
0
I am new to GUI development. What is the best GUI development package for python on linux (ubuntu being more specific)?
GUI development package
0.099668
0
0
238
3,897,140
2010-10-09T17:31:00.000
0
1
0
1
python,apache
3,898,807
2
false
1
0
You'd need to show your apache configuration to say for certain, but it seems that Apache isn't actually using mod_cgi to serve the index.cgi script. In your configuration there should be something like 'LoadModule mod_cgi'. It should be uncommented (i.e., it shouldn't have a '#' at the beginning of the line). If you want to test this, then write a 'Hello World' cgi script and put it (temporarily) in place of index.cgi and see if you can get that to run. Let us know the results.
2
0
0
I have a CGI script (pwyky) that I called index.cgi, put in directory wiki/, and setup Apache to call localhost/wiki/index.cgi when I access localhost/wiki. I'm getting errors when I'm trying to use this application -- it creates a page with links like "http://localhost/wiki/@edit/index", but when I click that link, Apace is trying to serve "wiki/@edit/index" as a file. I suspect that I need to get Apache to pass /@edit/index into index.cgi. In particular, looking through index.cgi, its looking for strings like "@edit" in REQUEST_URI environment variable. Any idea how to fix this?
URL rewriting question
0
0
0
762
3,897,140
2010-10-09T17:31:00.000
0
1
0
1
python,apache
3,908,016
2
true
1
0
I found the problem, it turned out this is done through RewriteEngine. Pwyky puts .htaccess file in the directory with all the settings for RewriteEngine, but because AllowOverride is "None" by default on MacOS, they were ignored. The solution was to change all "AllowOverride" directives to "All"
2
0
0
I have a CGI script (pwyky) that I called index.cgi, put in directory wiki/, and setup Apache to call localhost/wiki/index.cgi when I access localhost/wiki. I'm getting errors when I'm trying to use this application -- it creates a page with links like "http://localhost/wiki/@edit/index", but when I click that link, Apace is trying to serve "wiki/@edit/index" as a file. I suspect that I need to get Apache to pass /@edit/index into index.cgi. In particular, looking through index.cgi, its looking for strings like "@edit" in REQUEST_URI environment variable. Any idea how to fix this?
URL rewriting question
1.2
0
0
762
3,897,650
2010-10-09T20:02:00.000
1
0
0
0
python,django,search,full-text-search,django-sphinx
4,121,651
1
true
1
0
Here's a shot in the dark - Try to get the name of your index in sphinx.conf same as the table_name you are trying to index. This is a quirk which is missed by lot of people.
1
0
0
I am trying out Sphinx search in my Django project. All setup done & it works but need some clarification from someone who has actually used this setup. In my Sphinx search while indexing, I have used 'name' as the field in my MySQL to be searchable & all other fields in sql_query to be as attributes (according to Sphinx lingo). So when I search from my Model instance in Django, I get the search results alright but it does not have the 'name' field in the search results. I get all the other attributes. However, I get the 'id' of the search term. Technically, I could get the 'name' by again querying MySQL but I want to avoid this. Is there anything I am not doing here?
Django Sphinx Text Search
1.2
1
0
395
3,898,411
2010-10-10T00:07:00.000
0
0
1
0
python
3,898,509
5
false
0
0
I've always used v3 primarily. "Hacking 3rd party libraries" to me is just like importing any other module. The only thing is since most stuff still uses v2 you have to know both versions and keep them straight when looking at others code.
5
2
0
Is 2.x still the norm or would you recommend just coding in v3 at this point?
Is it time to cut over to Python 3.x now or not?
0
0
0
219
3,898,411
2010-10-10T00:07:00.000
0
0
1
0
python
3,898,448
5
false
0
0
My main use of Python is Django. Support for 3.x for this framework still lies in the future, unfortunately, and who knows about any related modules - so no, it's not quite time for many people. I actually bought Python 3 books last year when I started learning Python, thinking "I'll just start with 3 from the beginning!". That didn't work out, though.
5
2
0
Is 2.x still the norm or would you recommend just coding in v3 at this point?
Is it time to cut over to Python 3.x now or not?
0
0
0
219
3,898,411
2010-10-10T00:07:00.000
0
0
1
0
python
3,898,444
5
false
0
0
Do the frameworks and libraries you use have Python 3 versions? Libraries you use for development, and does your deploy stack support Python 3? Many Python projects have a lot of dependancies, especially web based projects, most of which aren't Py3K ready yet. If your stack is good, sure - Python 3 is the future, might as well embrace it now.
5
2
0
Is 2.x still the norm or would you recommend just coding in v3 at this point?
Is it time to cut over to Python 3.x now or not?
0
0
0
219
3,898,411
2010-10-10T00:07:00.000
0
0
1
0
python
3,898,418
5
false
0
0
Google App Engine documentation states it uses Python 2.5 Today I happened to notice that Python Imaging Library is till not released for 3.x. So, if you need those libraries or services, I guess you should wait.
5
2
0
Is 2.x still the norm or would you recommend just coding in v3 at this point?
Is it time to cut over to Python 3.x now or not?
0
0
0
219
3,898,411
2010-10-10T00:07:00.000
3
0
1
0
python
3,898,422
5
true
0
0
Python 3 is still a long way off having universal support from tools, libraries and distros, so its use in production would depend very much on whether the bits you need (or are likely to need in the near future) have been ported. For exploratory, educational and other uses, it depends very much on your own proclivity for living on the bleeding edge. If you are happy building from source and debugging and hacking third-party libraries to get things working, then you'll probably have no issues with Python 3. Otherwise, stick to the latest your distro offers, and if it is stuck on a really old Python — CentOS is still on 2.4! — you have my commiserations. Personally, I steer clear of CentOS for precisely this reason.
5
2
0
Is 2.x still the norm or would you recommend just coding in v3 at this point?
Is it time to cut over to Python 3.x now or not?
1.2
0
0
219
3,898,740
2010-10-10T02:20:00.000
3
0
1
0
python,timer
3,898,829
2
true
0
0
I think its a bad idea to use Timers in your case. Using the delayed threads in python will result in more complex code, less accuracy, and quite possible worse performance. Basically, the rule is that if you think you need threads, you don't. Very few programs benefit from the use of threads. I don't know what you are doing for input. You make reference to multiple players and I'm not sure whether thats on a single keyboard or perhaps networked. Regardless, your current strategy of a main loop may well be the best strategy. Although without seeing how your main loop operates its hard to say for certain.
2
4
0
I am working on a text-based game in Python 3.1 that would use timing as it's major source of game play. In order to do this effectively (rather than check the time every mainloop, my current method, which can be inaccurate, and slow if multiple people are playing the game at once) I was thinking about using the Threading.Timer class. Is it a bad thing to have multiple timers going at the same time? if so, how many timers is recommended? For example, the user inputs to start the game. every second after the game starts it decides whether or not something happens, so there's a Timer(1) for every user playing at the same time. If something happens, the player has a certain time to react to it, so a timer must be set for that. If the user reacts quickly enough, that timer needs to end and it will set a new timer depending on what's going to happen next, etc
Is using multiple Timers in Python dangerous?
1.2
0
0
2,394
3,898,740
2010-10-10T02:20:00.000
1
0
1
0
python,timer
3,898,754
2
false
0
0
It should be perfectly safe to have multiple timers going at the same time. Beware that it may not give much of a performance boost, as the CPython interpreter (the standard Python interpreter) uses a GIL (Global Interpreter Lock) which makes threading stuff a bit.... slow.
2
4
0
I am working on a text-based game in Python 3.1 that would use timing as it's major source of game play. In order to do this effectively (rather than check the time every mainloop, my current method, which can be inaccurate, and slow if multiple people are playing the game at once) I was thinking about using the Threading.Timer class. Is it a bad thing to have multiple timers going at the same time? if so, how many timers is recommended? For example, the user inputs to start the game. every second after the game starts it decides whether or not something happens, so there's a Timer(1) for every user playing at the same time. If something happens, the player has a certain time to react to it, so a timer must be set for that. If the user reacts quickly enough, that timer needs to end and it will set a new timer depending on what's going to happen next, etc
Is using multiple Timers in Python dangerous?
0.099668
0
0
2,394
3,898,988
2010-10-10T04:11:00.000
1
0
0
0
python,wxpython,frame,send
3,906,746
2
false
0
1
I'd definitely use PubSub as it's probably the cleanest way I can think of to do it. You can also do it with wx.PostEvent or use a modal frame.
1
1
0
I'm writing a small app which has 2 separate frames. The first frame is like a video player controller. It has Play/Stop/Pause buttons etc. It's named controller.py. The second frame contains OpenGL rendering and many things inside it, but everything is wrapped inside a Frame() class as the above. It's named model.py. I'm up to the final part where I have to "join" these two together. Does anyone know how to control a frame (model.py) from another frame (controller.py)? I would like to do something like a movie player when you clicks play it pops up a new window and play until the stop button is clicked. If you know how, please let me know. (Just tell me in general no need to specific).
How to control a frame from another frame?
0.099668
0
0
669
3,900,403
2010-10-10T13:03:00.000
1
0
0
0
python,sockets,serial-port
3,900,446
2
false
0
0
The simplest way is to simply accept a connection, handle the request, and close the connection. This way, your program handles only one request at a time. An alternative is to use locking or semaphores, to prevent multiple clients accessing the RS232 port simultaneously.
1
1
0
I need to expose an RS232 connection to clients via a network socket. I plan to write in python a TCP socket server which will listen on some port, allow client to connect and handle outgoing and manage and control requests and replies to from the R2232 port. My question is, how do I synchronize the clients, each client will send some string to the serial port and after the reply is sent back I need to return that client the result. Only then do I need to process the next request. How to I synchronize access to the serial port ?
Writing a TCP to RS232 driver
0.099668
0
1
1,048
3,901,144
2010-10-10T16:33:00.000
37
0
1
0
python,boolean
3,901,151
5
false
0
0
The former tests trueness, whereas the latter tests for identity with None. Lots of values are false, such as False, 0, '', and None, but only None is None.
1
49
0
It appears that "if x" is almost like short-hand for the longer "if x is not None" syntax. Are they functionally identical or are there cases where for a given value of x the two would evaluate differently? I would assume the behavior should also be identical across Python implementations - but if there are subtle differences it would be great to know.
Difference between "if x" and "if x is not None"
1
0
0
21,281
3,901,444
2010-10-10T17:58:00.000
2
0
1
0
python
3,901,628
5
false
0
0
You might want to rethink how you're representing your numbers. It might be best to represent all values as integers and then format them later when you need to print or display your output. This will give you the freedom of not worrying about floating-point errors and additionally will let you use math.ceil.
1
0
0
I just started programming in python not long ago, and I'm having trouble figuring out the rounding issue when it comes to tax and money. I can't seem to get decimals to always round up to the nearest hundredths place. for instance, in our state, sales takes is 9.5%, so a purchase of 5 dollars would make tax $.48, but in reality its $.475. I've tried math.ceil, but it seems like that only works to the nearest integer. Is there a simple way to enable a round up on any thousands digit? (ex .471 would round to .48) Thanks
I'm new to python, and trying to program a sales tax button for a calculator
0.07983
0
0
1,968
3,901,961
2010-10-10T19:59:00.000
0
0
0
0
python,orm,metaprogramming,introspection,relationships
3,902,410
3
true
0
0
So far, I see the only one technique covering more than two tables in relation. A table X is assumed related to table Y, if and only if X is referenced to Y no more than one table away. That is: "Zero tables away" means X contains the foreign key to Y. No big deal, that's how we detect many-to-ones. "One table away" means there is a table Z which itself has a foreign key referencing table X (these are easy to find), and a foreign key referencing table Y. This reduces the scope of traits to look for a lot (we don't have to care if the intermediary table has any other attributes), and it covers any number of tables tied together in a MTM relation. If there are some interesting links or other methods, I'm willing to hear them.
3
2
0
I'm currently busy making a Python ORM which gets all of its information from a RDBMS via introspection (I would go with XRecord if I was happy with it in other respects) — meaning, the end-user only tells which tables/views to look at, and the ORM does everything else automatically (if it makes you actually write something and you're not looking for weird things and dangerous adventures, it's a bug). The major part of that is detecting relationships, provided that the database has all relevant constraints in place and you have no naming conventions at all — I want to be able to have this ORM work with a database made by any crazy DBA which has his own views on what the columns and tables should be named like. And I'm stuck at many-to-many relationships. First, there can be compound keys. Then, there can be MTM relationships with three or more tables. Then, a MTM intermediary table might have its own data apart from keys — some data common to all tables it ties together. What I want is a method to programmatically detect that a table X is an intermediary table tying tables A and B, and that any non-key data it has must belong to both A and B (and if I change a common attribute from within A, it should affect the same attribute in B). Are there common algorithms to do that? Or at least to make guesses which are right in 80% of the cases (provided the DBA is sane)?
What are methods of programmatically detecting many-to-many relationships in a RDMBS?
1.2
1
0
241
3,901,961
2010-10-10T19:59:00.000
1
0
0
0
python,orm,metaprogramming,introspection,relationships
3,902,041
3
false
0
0
If you have to ask, you shouldn't be doing this. I'm not saying that to be cruel, but Python already has several excellent ORMs that are well-tested and widely used. For example, SQLAlchemy supports the autoload=True attribute when defining tables that makes it read the table definition - including all the stuff you're asking about - directly from the database. Why re-invent the wheel when someone else has already done 99.9% of the work? My answer is to pick a Python ORM (such as SQLAlchemy) and add any "missing" functionality to that instead of starting from scratch. If it turns out to be a good idea, release your changes back to the main project so that everyone else can benefit from them. If it doesn't work out like you hoped, at least you'll already be using a common ORM that many other programmers can help you with.
3
2
0
I'm currently busy making a Python ORM which gets all of its information from a RDBMS via introspection (I would go with XRecord if I was happy with it in other respects) — meaning, the end-user only tells which tables/views to look at, and the ORM does everything else automatically (if it makes you actually write something and you're not looking for weird things and dangerous adventures, it's a bug). The major part of that is detecting relationships, provided that the database has all relevant constraints in place and you have no naming conventions at all — I want to be able to have this ORM work with a database made by any crazy DBA which has his own views on what the columns and tables should be named like. And I'm stuck at many-to-many relationships. First, there can be compound keys. Then, there can be MTM relationships with three or more tables. Then, a MTM intermediary table might have its own data apart from keys — some data common to all tables it ties together. What I want is a method to programmatically detect that a table X is an intermediary table tying tables A and B, and that any non-key data it has must belong to both A and B (and if I change a common attribute from within A, it should affect the same attribute in B). Are there common algorithms to do that? Or at least to make guesses which are right in 80% of the cases (provided the DBA is sane)?
What are methods of programmatically detecting many-to-many relationships in a RDMBS?
0.066568
1
0
241
3,901,961
2010-10-10T19:59:00.000
0
0
0
0
python,orm,metaprogramming,introspection,relationships
3,902,030
3
false
0
0
Theoretically, any table with multiple foreign keys is in essence a many-to-many relation, which makes your question trivial. I suspect that what you need is a heuristic of when to use MTM patterns (rather than standard classes) in the object model. In that case, examine what are the limitations of the patterns you chose. For example, you can model a simple MTM relationship (two tables, no attributes) by having lists as attributes on both types of objects. However, lists will not be enough if you have additional data on the relationship itself. So only invoke this pattern for tables with two columns, both with foreign keys.
3
2
0
I'm currently busy making a Python ORM which gets all of its information from a RDBMS via introspection (I would go with XRecord if I was happy with it in other respects) — meaning, the end-user only tells which tables/views to look at, and the ORM does everything else automatically (if it makes you actually write something and you're not looking for weird things and dangerous adventures, it's a bug). The major part of that is detecting relationships, provided that the database has all relevant constraints in place and you have no naming conventions at all — I want to be able to have this ORM work with a database made by any crazy DBA which has his own views on what the columns and tables should be named like. And I'm stuck at many-to-many relationships. First, there can be compound keys. Then, there can be MTM relationships with three or more tables. Then, a MTM intermediary table might have its own data apart from keys — some data common to all tables it ties together. What I want is a method to programmatically detect that a table X is an intermediary table tying tables A and B, and that any non-key data it has must belong to both A and B (and if I change a common attribute from within A, it should affect the same attribute in B). Are there common algorithms to do that? Or at least to make guesses which are right in 80% of the cases (provided the DBA is sane)?
What are methods of programmatically detecting many-to-many relationships in a RDMBS?
0
1
0
241
3,902,008
2010-10-10T20:17:00.000
5
0
0
0
python,latex,pyqt,sympy
6,916,267
2
false
0
1
If you just need simple rendering using python, how about trying ipython 0.11 with qtconsole using sympy profile(ipython qtconsole --profile=sympy). It did implement matplotlib, but I consider it quite clean considering mathematical expressions can be rendered directly on the qtconsole. Need to install pyzmq module.
1
5
0
I am hoping to use PyQt to produce an application that will display an equation entered by the user. I had considered matplotlib, but this seems like overkill as I would only be using it to render the latex. I need to use SymPy anyway, so I was hoping there would be a way to use it to do the rendering also, preferably producing an SVG file for PyQt to use. I hope this makes sense - many thanks in advance for any help/advice. Best wishes, Geddes
Is it possible for SymPy to render LaTeX for use in a GUI?
0.462117
0
0
2,067
3,902,032
2010-10-10T20:22:00.000
1
0
0
0
mono,ironpython
3,911,162
1
false
0
0
Did you build IronPython yourself? Signing is kind of a PITA and you'll need to provide your own full key to get a real signature. We do include the MS public key in the distribution but this can only be used for delay signing. We do have delay signing turned on in the build which might result in a delay signed build even if you use a full key (I'm not sure what the compilers do here). You can probably fully sign the assembly using sn or Mono's equivalent. You also may be able to disable verification before installing in the GAC by using sn as well (this is what we when we develop IronPython).
1
1
0
I tried to use gacutil (mono) for IronPython, but I got the following error. sudo gacutil -i IronPython.dll Password: Failure adding assembly IronPython.dll to the cache: Strong name cannot be verified for delay-signed assembly What does this mean? Any solution to this problem?
GAC (gacutil) not working with IronPython.dll on Mono
0.197375
0
0
597
3,902,996
2010-10-11T01:28:00.000
-2
0
1
0
python,debugging,ide
3,903,016
6
false
0
0
To start coding in a file, just open a new file and start typing.
4
3
0
This obviously an extremely novice question, but I've installed Python 2.7 and started reading the manual. However I looked and looked, and couldn't understand how to start programming a file rather than writing in interactive mode. One book that was online suggested quit(), which surprise -- quit the program. Should coding be done in a different program? I'm using IDLE (Python GUI). Can coding not be done within that program?
How to get out of interactive mode in Python
-0.066568
0
0
7,387
3,902,996
2010-10-11T01:28:00.000
0
0
1
0
python,debugging,ide
16,851,751
6
false
0
0
use new window tool in the file icon,in the python idle itself to write a program
4
3
0
This obviously an extremely novice question, but I've installed Python 2.7 and started reading the manual. However I looked and looked, and couldn't understand how to start programming a file rather than writing in interactive mode. One book that was online suggested quit(), which surprise -- quit the program. Should coding be done in a different program? I'm using IDLE (Python GUI). Can coding not be done within that program?
How to get out of interactive mode in Python
0
0
0
7,387
3,902,996
2010-10-11T01:28:00.000
0
0
1
0
python,debugging,ide
3,903,066
6
false
0
0
Push new to start making your own script file. Then when you are ready to test click run and then you can watch the results in the interactive mode, and even try new things as if you were adding code to the end of your script file, its a very useful app for debugging, testing and trying new things. Also in the options you can change the way python opens your scripts when you click edit from windows, you can set it so that it opens the interactive shell or just the editor.
4
3
0
This obviously an extremely novice question, but I've installed Python 2.7 and started reading the manual. However I looked and looked, and couldn't understand how to start programming a file rather than writing in interactive mode. One book that was online suggested quit(), which surprise -- quit the program. Should coding be done in a different program? I'm using IDLE (Python GUI). Can coding not be done within that program?
How to get out of interactive mode in Python
0
0
0
7,387
3,902,996
2010-10-11T01:28:00.000
2
0
1
0
python,debugging,ide
3,903,006
6
false
0
0
Yes, coding should be done in a different program. The interactive shell is very useful but it's not an editor.
4
3
0
This obviously an extremely novice question, but I've installed Python 2.7 and started reading the manual. However I looked and looked, and couldn't understand how to start programming a file rather than writing in interactive mode. One book that was online suggested quit(), which surprise -- quit the program. Should coding be done in a different program? I'm using IDLE (Python GUI). Can coding not be done within that program?
How to get out of interactive mode in Python
0.066568
0
0
7,387
3,904,809
2010-10-11T09:00:00.000
1
0
0
0
python,django,django-forms
3,910,066
1
false
1
0
You can either make the form have an additional form field for the checkbox. And override it's save method to fill the model fields accordingly. Or you can make a custom form field widget that would hold both HTML input fields and produce the appropriate python value from the inputs and vice versa. The first option being the simpler to implement, and wiser if you need this functionality only in one form. Either way, I'd reconsider using a null value to mean anything except no value entered. You could make it so that the Integer field holds -1 to mean unlimited if all other user specified values can only be positive. Or add another boolean model field to hold the value for this checkbox.
1
2
0
I am making a form in Django. The field to display is a numeric field representing some limit. It's possible for there to be no limit. Rather than force the user to enter some strange number to mean unlimited (e.g. -1), I'd like there to be a radio button, with 2 options: "Unlimited" and the second option being a text box that the user can enter the value into. The original model only has the IntegerField which can be null. A null value is used to mean unlimited. Is there some way I can make a FormField of this field that will include this checkbox functionality? I know I can hand write the HTML myself, I'm wondering if there is a already made django field/widget that'll do this.
Django - Form widget with a checkbox to choose between unlimited or a textbox for a number
0.197375
0
0
734
3,905,509
2010-10-11T10:51:00.000
0
0
1
0
python,regex
3,905,595
2
false
0
0
If you absolutly want regexes you can use (?<=\\autocite)(.*?)\\autocite(.*) and replace with \1\2. But @Ignacio Vazquez-Abrams answer is way better an efficient.
1
0
0
Given lines that look like the following: Blah \cite[9.1173]{Joyce:1986aa}\autocite[42]{Kenner:1970ab}\autocite[108]{Hall:1960aa} bbb.\n I’d like to remove the second (and any subsequent) occurrence of \autocite, resulting in the following: Blah \autocite[9.1173]{Joyce:1986aa}[42]{Kenner:1970ab}[108]{Hall:1960aa} bbb.\n I’m struggling to express this in regex form (I’m using the python 2.7 RE module), however, as I’m not sure how to formulate “remove only the second and subsequent occurrences of \autocite when followed by […]{…}, until a space or period is encountered”.
How to remove repeating non-adjacent string
0
0
0
146
3,905,791
2010-10-11T11:33:00.000
1
0
0
1
python,twisted,factory
3,906,174
1
false
1
0
No. Write a class that does the interaction with one user. In connectionMade you check if a instance of this class already exists, if not you make a new one and store it on the factory, ie in a { addr : handler } dict. If the connection exists alreay you get the old handler from the factory.
1
0
0
Hey, I got a ReconnectingClientFactory and I wonder if I can somehow define protocol-instance-based connectionMade/connectionLost callbacks so that i can use the factory to connect to different hosts ans distinguish between each connection. Thanks in advance.
Twisted factory protocol instance based callback
0.197375
0
0
499
3,905,883
2010-10-11T11:48:00.000
2
1
0
0
python,multithreading,debugging,deadlock,futex
4,533,967
2
false
1
0
Dear Helmut, I've the same problem with one thread hanging on FUTEXT_WAIT_PRIVATE. It seems you have solved the issue. Can you share more information about the solution? UPD: The reason for the lock was finally found (at least for my case): it was due to import lock in Python. Consider following situation: file1.py: import file2 file2.py: create thread "thread2" run "thread2" wait until "thread2" finish with some function (let's say go Go()) def Go(): import some_module .... Here the import in Go() would hang up since the import is locked in the main thread (by import file2) which will not be released until Go() finishes. The user will see in strace hang on FUTEX_WAIT_PRIVATE. To work around this place the code executed during the import of file2 into Do() function and run it after importing file2: import file2 file2.Do()
2
2
0
I have a Python daemon running in production. It employs between 7 and 120 threads. Recently the smallest instance (7 threads) started to show hangs while all other instances never showed this kind of problem. Attaching strace to the python process shows that all threads are calling futex FUTEX_WAIT_PRIVATE, so they are probably trying to lock something. How would you debug such a problem? Note that this is a production system running from flash memory, so disk writes are constrained, too.
Python hangs in futex calls
0.197375
0
0
7,410
3,905,883
2010-10-11T11:48:00.000
4
1
0
0
python,multithreading,debugging,deadlock,futex
3,913,056
2
true
1
0
The observation was slightly incorrect. One thread wasn't calling futex, but instead swapping while holding the gil. Since the machine in question is low hardware this swapping took very long and seemed to be a deadlock. The underlying problem is a memory leak. :-(
2
2
0
I have a Python daemon running in production. It employs between 7 and 120 threads. Recently the smallest instance (7 threads) started to show hangs while all other instances never showed this kind of problem. Attaching strace to the python process shows that all threads are calling futex FUTEX_WAIT_PRIVATE, so they are probably trying to lock something. How would you debug such a problem? Note that this is a production system running from flash memory, so disk writes are constrained, too.
Python hangs in futex calls
1.2
0
0
7,410
3,906,903
2010-10-11T14:00:00.000
9
0
1
0
python,networking,character,bits
3,906,938
3
false
0
0
\r is a carriage return (0x0d), the t is a t.
1
0
0
maybe this is a noob question, but I'm receiving some data over TCP and when I look at the string I get the following: \x00\r\xeb\x00\x00\x00\x00\x01t\x00 What is that \r character, and what does the t in \x01t mean? I've tried Googling, but I'm not sure what to Google for... thanks.
Non-binary(hex) characters in string received over TCP with Python
1
0
1
819
3,908,062
2010-10-11T16:23:00.000
3
0
0
0
python,user-interface,google-app-engine,ironpython
3,908,074
1
false
1
1
Google's Google App Engine can only run pure python code, and not even all Python is supported. No, you can't do things like IronPython. If you want to use Python, I'd learn Django. If you want something closer to .NET, I'd go with Java.
1
3
0
I'm developing a simple Python program with a (dynamic) form interface, but it needs to run on Google App Engine. I understand that IronPython lets one use Visual Studio's drag-and-drop interface builder and classes while programming with Python, but will this be compatible with Google App Engine?
Can I use IronPython to develop GUIs for Google App Engine?
0.53705
0
0
651
3,910,223
2010-10-11T21:53:00.000
2
0
0
0
python,trusted-vs-untrusted
3,910,435
7
false
0
0
It's impossible to provide an absolute solution for this because the definition of 'bad' is pretty hard to nail down. Is opening and writing to a file bad or good? What if that file is /dev/ram? You can profile signatures of behavior, or you can try to block anything that might be bad, but you'll never win. Javascript is a pretty good example of this, people run arbitrary javascript code all the time on their computers -- it's supposed to be sandboxed but there's all sorts of security problems and edge conditions that crop up. I'm not saying don't try, you'll learn a lot from the process. Many companies have spent millions (Intel just spent billions on McAffee) trying to understand how to detect 'bad code' -- and every day machines running McAffe anti-virus get infected with viruses. Python code isn't any less dangerous than C. You can run system calls, bind to C libraries, etc.
4
8
0
Let's say there is a server on the internet that one can send a piece of code to for evaluation. At some point server takes all code that has been submitted, and starts running and evaluating it. However, at some point it will definitely bump into "os.system('rm -rf *')" sent by some evil programmer. Apart from "rm -rf" you could expect people try using the server to send spam or dos someone, or fool around with "while True: pass" kind of things. Is there a way to coop with such unfriendly/untrusted code? In particular I'm interested in a solution for python. However if you have info for any other language, please share.
sandbox to execute possibly unfriendly python code
0.057081
0
1
5,900
3,910,223
2010-10-11T21:53:00.000
0
0
0
0
python,trusted-vs-untrusted
3,910,850
7
false
0
0
I think a fix like this is going to be really hard and it reminds me of a lecture I attended about the benefits of programming in a virtual environment. If you're doing it virtually its cool if they bugger it. It wont solve a while True: pass but rm -rf / won't matter.
4
8
0
Let's say there is a server on the internet that one can send a piece of code to for evaluation. At some point server takes all code that has been submitted, and starts running and evaluating it. However, at some point it will definitely bump into "os.system('rm -rf *')" sent by some evil programmer. Apart from "rm -rf" you could expect people try using the server to send spam or dos someone, or fool around with "while True: pass" kind of things. Is there a way to coop with such unfriendly/untrusted code? In particular I'm interested in a solution for python. However if you have info for any other language, please share.
sandbox to execute possibly unfriendly python code
0
0
1
5,900
3,910,223
2010-10-11T21:53:00.000
2
0
0
0
python,trusted-vs-untrusted
3,910,730
7
false
0
0
I would seriously consider virtualizing the environment to run this stuff, so that exploits in whatever mechanism you implement can be firewalled one more time by the configuration of the virtual machine. Number of users and what kind of code you expect to test/run would have considerable influence on choices btw. If they aren't expected to link to files or databases, or run computationally intensive tasks, and you have very low pressure, you could be almost fine by just preventing file access entirely and imposing a time limit on the process before it gets killed and the submission flagged as too expensive or malicious. If the code you're supposed to test might be any arbitrary Django extension or page, then you're in for a lot of work probably.
4
8
0
Let's say there is a server on the internet that one can send a piece of code to for evaluation. At some point server takes all code that has been submitted, and starts running and evaluating it. However, at some point it will definitely bump into "os.system('rm -rf *')" sent by some evil programmer. Apart from "rm -rf" you could expect people try using the server to send spam or dos someone, or fool around with "while True: pass" kind of things. Is there a way to coop with such unfriendly/untrusted code? In particular I'm interested in a solution for python. However if you have info for any other language, please share.
sandbox to execute possibly unfriendly python code
0.057081
0
1
5,900
3,910,223
2010-10-11T21:53:00.000
0
0
0
0
python,trusted-vs-untrusted
3,910,895
7
false
0
0
Unless I'm mistaken (and I very well might be), this is much of the reason behind the way Google changed Python for the App Engine. You run Python code on their server, but they've removed the ability to write to files. All data is saved in the "nosql" database. It's not a direct answer to your question, but an example of how this problem has been dealt with in some circumstances.
4
8
0
Let's say there is a server on the internet that one can send a piece of code to for evaluation. At some point server takes all code that has been submitted, and starts running and evaluating it. However, at some point it will definitely bump into "os.system('rm -rf *')" sent by some evil programmer. Apart from "rm -rf" you could expect people try using the server to send spam or dos someone, or fool around with "while True: pass" kind of things. Is there a way to coop with such unfriendly/untrusted code? In particular I'm interested in a solution for python. However if you have info for any other language, please share.
sandbox to execute possibly unfriendly python code
0
0
1
5,900
3,911,319
2010-10-12T02:41:00.000
2
0
1
0
python,list,formatting
3,911,330
4
false
0
0
Step 1. Convert the list to a dictionary. Each element is a list of values with a common key. (Hint: The key is the first value of each pair) Step 2. Now format each dictionary as key, space, value list.
1
1
0
I've got a list like [(1, 2), (1, 8), (2, 3), (2, 7), (2, 8), (2, 9), (3, 1), (3, 2), (3, 5), (3, 6), (3, 7), (3, 7), (3, 9)] I want to make it looks like [('1',' ', '2', '8'), ('2', ' ', '3', '7', '8', '9'), ('3', " ", '2', '5', '6', '7', '7', '9')] How can I code this loop? Really tried times, and nothing came up. Please help~~
Python, format this list
0.099668
0
0
1,143
3,911,494
2010-10-12T03:31:00.000
0
0
1
1
python,google-app-engine,dictionary,python-2.5
3,911,537
3
false
0
0
you can sort a dict.items() list (of tuples) .. can't?
2
1
0
I'm new to Python, and using Google App Engine, which is currently running only Python 2.5. Are there any built-in ways of doing an ordered dictionary, or do I have to implement something custom?
Possible to do ordered dictionary in python 2.5 (due to GAE)?
0
0
0
673
3,911,494
2010-10-12T03:31:00.000
0
0
1
1
python,google-app-engine,dictionary,python-2.5
3,912,743
3
false
0
0
OrderedDict is new in 2.7, so no, there's no built-in way to do this - you'll have to implement your own. Usually, an ordered dictionary is implemented as a dictionary of linked list nodes, linked in traversal order. This should be fairly straightforward to implement yourself.
2
1
0
I'm new to Python, and using Google App Engine, which is currently running only Python 2.5. Are there any built-in ways of doing an ordered dictionary, or do I have to implement something custom?
Possible to do ordered dictionary in python 2.5 (due to GAE)?
0
0
0
673
3,911,519
2010-10-12T03:38:00.000
3
0
1
0
python,string-concatenation
3,911,527
1
false
0
0
Homework? Did you submit the result of the expression, or the expression itself? ",".join([name1, name2, name3]) Or whatever you used? Edit: You mention that you submitted ("name1", "name2", "name3") - which would not return the concatenated names - but rather those stings. If you wanted to do it like this (a little less elegant then the version I put above) you could try: name1 + "," + name2 + "," + name3 The difference being the quotations (") around the names - are stopping you from using the variables provided. Edit2: This is how I understand the question you were asked. They want you to submit to them, an expression that will return the values assigned to the name1, name2 and name3 variables (whatever they may be) - There are two examples of such expressions above - which concatenate the three name variables, and add a comma between them - have you tried submitting either of the examples above?
1
1
0
The question i'm working on asks me to "write an expression whose value is the concatenation of the three str values associated with name1 , name2 , and name3" , separated by commas." "So if name1 , name2 , and name3 , were (respectively) "Neville", "Dean", and "Seamus", your expression's value would be "Neville,Dean,Seamus". " The answer that i submitted is "name1,name2,name3" but when i click "submit" the message informs of a logical error within my code and that my expression didn't return the correct value. What have i done wrong?
What have i done wrong? (python help)
0.53705
0
0
2,802
3,911,897
2010-10-12T05:26:00.000
1
1
1
0
python,multithreading,multiprocessing,concurrency
3,913,601
8
false
0
0
Take the hint. CPU intensive programs can also be made into multiple processes. Multiple processes and a pipeline to pass status around can often have outstanding performance. Rather than fish around randomly for other languages, do this. Decompose the problem into a pipeline of steps that can be done concurrently. In the shell, the top-level script is this: a.py | b.py | c.py | d.py... Write each step as a very small Python loop that reads from sys.stdin and writes to sys.stdout. Interesting, this is the default for raw_input() and print() making things simple. Measure the performance. You'll -- correctly -- spend all your time designing your algorithm. You'll spend little time coding or learning a new language. You'll trivially tie up every core on every CPU available to you. You'll spend no time on thread synchronization or other foolishness. This kind of thing works very, very well for "CPU Intensive" applications.
2
3
0
I now primarily write in python, however I am looking for a language that is more thread friendly (not JAVA,C#,C or C++). Python's threads are good when they are IO bound but it's coming up short when I am doing something CPU intensive. Any ideas? Thanks, James
"Pythonic" multithreaded (Concurrent) language
0.024995
0
0
457
3,911,897
2010-10-12T05:26:00.000
1
1
1
0
python,multithreading,multiprocessing,concurrency
3,911,913
8
false
0
0
to overcome GIL, you can try interpreting python language with jython instead of cpython
2
3
0
I now primarily write in python, however I am looking for a language that is more thread friendly (not JAVA,C#,C or C++). Python's threads are good when they are IO bound but it's coming up short when I am doing something CPU intensive. Any ideas? Thanks, James
"Pythonic" multithreaded (Concurrent) language
0.024995
0
0
457
3,912,579
2010-10-12T07:53:00.000
2
0
0
0
python,django,installation
3,912,677
1
true
1
0
It is very likely that the py extension is linked with the editor rather than the Python interpreter. Right-click on a py file and click "Open with" then select the default program and choose 'C:...\Python2x\python.exe' That should fix the pb
1
1
0
I've got an issue when installing Django. The official guide says open cmd with administrator privileges and run "setup.py install" I did this but then the system default python editor came out, I don't know how to do anymore, please help me~
Issue happens when installing Django on Windows 7
1.2
0
0
494
3,912,910
2010-10-12T08:49:00.000
1
0
0
0
python,urllib,urlopen
3,912,922
1
true
0
0
It's an optional header, so no. See if it exists, and if not then fall back to checking the URL.
1
1
0
I'm using urllib.urlopen to read a file from a URL. What is the best way to get the filename? Do servers always return the Content-Disposition header? Thanks.
Get filename when using urllib.urlopen
1.2
0
1
575
3,913,217
2010-10-12T09:30:00.000
-1
1
1
0
python,programming-languages,namespaces
3,913,281
6
false
0
0
If you make a big program with someone else, you could write your own part of the program as you want. All variables in the file will be private, there will be no collisions. When you write PHP programs, it is easy to rewrite global variables by mistake. In python you can import other modules variables if you want, and they will be "global" on your module. You could think one file one object in Python. When you write PHP programs you can achieve the same by writing classes with instance variables.
2
47
0
I have just started learning Python & have come across "namespaces" concept in Python. While I got the jist of what it is, but am unable to appreciate the gravity of this concept. Some browsing on the net revealed that one of the reasons going against PHP is that it has no native support for namespaces. Could someone explain how to use namespaces & how this feature makes programming better (not just in Python, as I assume namespaces in not a concept limited to a particular language). I am predominantly coming from Java and C programming backgrounds.
What are Python namespaces all about
-0.033321
0
0
29,735
3,913,217
2010-10-12T09:30:00.000
49
1
1
0
python,programming-languages,namespaces
3,913,488
6
true
0
0
Namespace is a way to implement scope. In Java (or C) the compiler determines where a variable is visible through static scope analysis. In C, scope is either the body of a function or it's global or it's external. The compiler reasons this out for you and resolves each variable name based on scope rules. External names are resolved by the linker after all the modules are compiled. In Java, scope is the body of a method function, or all the methods of a class. Some class names have a module-level scope, also. Again, the compiler figures this out at compile time and resolves each name based on the scope rules. In Python, each package, module, class, function and method function owns a "namespace" in which variable names are resolved. Plus there's a global namespace that's used if the name isn't in the local namespace. Each variable name is checked in the local namespace (the body of the function, the module, etc.), and then checked in the global namespace. Variables are generally created only in a local namespace. The global and nonlocal statements can create variables in other than the local namespace. When a function, method function, module or package is evaluated (that is, starts execution) a namespace is created. Think of it as an "evaluation context". When a function or method function, etc., finishes execution, the namespace is dropped. The variables are dropped. The objects may be dropped, also.
2
47
0
I have just started learning Python & have come across "namespaces" concept in Python. While I got the jist of what it is, but am unable to appreciate the gravity of this concept. Some browsing on the net revealed that one of the reasons going against PHP is that it has no native support for namespaces. Could someone explain how to use namespaces & how this feature makes programming better (not just in Python, as I assume namespaces in not a concept limited to a particular language). I am predominantly coming from Java and C programming backgrounds.
What are Python namespaces all about
1.2
0
0
29,735
3,914,289
2010-10-12T11:47:00.000
0
1
1
0
python,module,packaging,pythonpath
3,914,361
3
false
0
0
You could set the PYTHONPATH as a global environment variable pointing to your Production code, and then in any shell in which you want to use the Development code, change the PYTHONPATH to point to that code. (Is that too simplistic? Have I missed something?)
1
2
0
I'm developing a Python utility module to help with file downloads, archives, etc. I have a project set up in a virtual environment along with my unit tests. When I want to use this module on the same computer (essentially as "Production"), I move the files to the mymodule directory in the ~/dev/modules/mymodule I keep all 3rd-party modules under ~/dev/modules/contrib. This contrib path is on my PYTHONPATH, but mymodule is NOT because I've noticed that if mymodule is on my PYTHONPATH, my unit tests cannot distinguish between the "Development" version and the "Production" version. But now if I want to use this common utility module, I have to manually add it to the PYTHONPATH. This works, but I'm sure there's a better, more automated way. What is the best way to have a Development and Production module on the same computer? For instance, is there a way to set PYTHONPATH dynamically?
Developing and using the same Python on the same computer
0
0
0
209
3,914,370
2010-10-12T11:56:00.000
0
0
0
0
python,pygtk
3,917,071
1
true
0
1
Checking gtk.gdk.screen_get_default() does it, however there seems no way to suppress the GTK warnings.
1
1
0
I have a pygtk application and would like to provide a text-based fallback mode for it. When mporting gtk without a X display available I see only a GtkWarning on stderr but no exception I could take advantage of and checking for DISPLAY seems like an ugly hack. How can I implement this?
Implementing a text-based fallback for pygtk applications
1.2
0
0
46
3,914,409
2010-10-12T12:01:00.000
2
0
1
0
python,windows,file
3,914,630
5
true
0
0
Notepad has no facilities for doing such from an external source. Short of hooking into the Windows windowing API, finding the text area, and populating it yourself.
2
1
0
I have a string called 's' and I want to open it in notepad at runtime without saving it in/as a file. Is there any way to achieve this in python?
open a string in notepad at runtime in python
1.2
0
0
2,872
3,914,409
2010-10-12T12:01:00.000
0
0
1
0
python,windows,file
3,914,473
5
false
0
0
No. Notepad does not read data from stdin, so passing it a file or OS-level file-like is the only way for it to display text.
2
1
0
I have a string called 's' and I want to open it in notepad at runtime without saving it in/as a file. Is there any way to achieve this in python?
open a string in notepad at runtime in python
0
0
0
2,872
3,914,725
2010-10-12T12:35:00.000
5
0
1
0
python,number-formatting
3,914,765
8
false
0
0
x = round(293.4662543, 2)
1
32
0
How to shorten the float result I got? I only need 2 digits after the dot. Sorry I really don't know how to explain this better in English... Thanks
How to turn a float number like 293.4662543 into 293.47 in python?
0.124353
0
0
103,306