Q_Id int64 337 49.3M | CreationDate stringlengths 23 23 | Users Score int64 -42 1.15k | Other int64 0 1 | Python Basics and Environment int64 0 1 | System Administration and DevOps int64 0 1 | Tags stringlengths 6 105 | A_Id int64 518 72.5M | AnswerCount int64 1 64 | is_accepted bool 2
classes | Web Development int64 0 1 | GUI and Desktop Applications int64 0 1 | Answer stringlengths 6 11.6k | Available Count int64 1 31 | Q_Score int64 0 6.79k | Data Science and Machine Learning int64 0 1 | Question stringlengths 15 29k | Title stringlengths 11 150 | Score float64 -1 1.2 | Database and SQL int64 0 1 | Networking and APIs int64 0 1 | ViewCount int64 8 6.81M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2,761,512 | 2010-05-03T22:01:00.000 | 8 | 0 | 0 | 0 | python,qt,qt4,pyqt,pyqt4 | 2,761,528 | 2 | true | 0 | 1 | Add a QShortcut and listen to its activated() signal, then perform the action in the slot.
Or you could reimplement QWidget and define keyPressEvent to what you like. Check for the event parameter's modifiers() and key() to see if they match with what you want. This listens for shortcut keys when the QWidget has focus. | 1 | 3 | 0 | i converted recently from wxpython to pyqt and im still facing alot of problems since im still noob in pyqt
so is it possible to detected if user pressed (CTRL+key ) in pyqt ? and how ?
i've been trying to find an answer for this for 3 days . if you know website or a good place to learn pyqt, it will be highly appreciated
thanx in advance | getting keyboard events with pyqt | 1.2 | 0 | 0 | 5,552 |
2,763,274 | 2010-05-04T06:33:00.000 | 1 | 0 | 0 | 0 | python,urllib2,urllib | 2,763,308 | 3 | false | 0 | 0 | You probably can use AJAX requests made from JavaScript that is a part of client-side.
Use server → client communication to give commands and necessary data to make a request
…and use AJAX communication from client to 3rd party server then. | 1 | 1 | 0 | I've written a Python application that makes web requests using the urllib2 library after which it scrapes the data. I could deploy this as a web application which means all urllib2 requests go through my web-server. This leads to the danger of the server's IP being banned due to the high number of web requests for many users. The other option is to create an desktop application which I don't want to do. Is there any way I could deploy my application so that I can get my web-requests through the client side. One way was to use Jython to create an applet but I've read that Java applets can only make web-requests to the server it is deployed on and the only way to to circumvent this is to create a server side proxy which leads us back to the problem of the server's ip getting banned.
This might sounds sound like and impossible situation and I'll probably end up creating a desktop application but I thought I'd ask if anyone knew of an alternate solution.
Thanks. | making urllib request in Python from the client side | 0.066568 | 0 | 1 | 1,085 |
2,763,541 | 2010-05-04T07:26:00.000 | 3 | 0 | 1 | 1 | python,windows,scripting | 2,763,663 | 1 | true | 0 | 0 | I think the easiest solution is make an external .bat file that executes your exe file and deletes it when finished. | 1 | 1 | 0 | I have written a Python script and compiled it into a MS Windows EXE file. I can modify the code, but how do I make it remove itself after running? | I am using Python on Windows. How do I delete my script after it is run? | 1.2 | 0 | 0 | 608 |
2,764,121 | 2010-05-04T09:21:00.000 | 1 | 0 | 1 | 0 | python,console,user-input | 2,764,151 | 2 | false | 0 | 0 | On *nix use select on sys.stdin to wait for a character, then .read() it in. On Windows use msvcrt.kbhit() and msvcrt.getch(). | 1 | 5 | 0 | I want someone to type words in the console, and autocomplete from a list when they hit "tab" key. However, raw_input won't return a string until someone hits [Enter].
How do I read characters into a variable until the user hits [Enter]?
*Note: I don't want to use import readline for autocompletion because of OS issues. | Python get raw_input but manually decide when string is done | 0.099668 | 0 | 0 | 825 |
2,766,787 | 2010-05-04T15:44:00.000 | 1 | 0 | 0 | 0 | python,http,streaming,metadata | 2,792,800 | 1 | true | 0 | 0 | Sounds like you might need some stepping stone projects before you're ready for this. There's no reason to use a low-level socket library for HTTP. There are great tools both command line utilities and python standard library modules like urlopen2 that can handle the low level TCP and HTTP specifics for you.
Do you know the URL where you data resides? Have you tried something simple on the command line like using cURL to grab the raw HTML and then some basic tools like grep to hunt down the info you need? I assume here the metadata is actually available as HTML as opposed to being in a binary format read directly by the radio streamer (which presumably is in flash perhaps?).
Hard to give you any specifics because your question doesn't include any technical details about your data source. | 1 | 0 | 0 | I'd like to extract the info string from an internet radio streamed over HTTP. By info string I mean the short note about the currently played song, band name etc.
Preferably I'd like to do it in python. So far I've tried opening a socket but from there I got a bunch of binary data that I could not parse...
thanks for any hints | Parse metadata from http live stream | 1.2 | 0 | 1 | 2,040 |
2,767,013 | 2010-05-04T16:16:00.000 | 6 | 1 | 1 | 1 | python,webserver | 2,767,055 | 3 | false | 0 | 0 | You can still use CGI if you want, but the normal approach these days is using WSGI on the Python side, e.g. through mod_wsgi on Apache or via bridges to FastCGI on other web servers. At least with mod_wsgi, I know of no inefficiencies with this approach.
BTW, your description of CGI ("create a new thread for each process") is inaccurate: what it does is create a new process for each query's service (and that process typically needs to open a database connection, import all needed modules, etc etc, which is what may make it slow even on platforms where forking a process, per se, is pretty fast, such as all Unix variants). | 1 | 1 | 0 | I think in the past python scripts would run off CGI, which would create a new thread for each process.
I am a newbie so I'm not really sure, what options do we have?
Is the web server pipeline that python works under any more/less effecient than say php? | When deploying python, what web server options do we have? is the process inefficient at all? | 1 | 0 | 0 | 232 |
2,767,382 | 2010-05-04T17:11:00.000 | 1 | 0 | 1 | 0 | python,virtualenv,easy-install,pip | 2,786,813 | 3 | false | 0 | 0 | I haven't actually tried this with those specific packages, but I would guess that a simple symlink from the global site-packages into the virtualenv's site-packages might work, and this is easily scriptable. | 1 | 16 | 0 | I'd usually prefer to create virtualenvs with --no-site-packages option for more isolation, and also because default python global packages includes quite a lot of packages, and usually most of them are not needed.
However I'd still want to keep a few select packages in global, like PIL or psycopg2. Is there a good way to include them into the virtualenv, that can also be automated easily? | Including global package into a virtualenv that has been created with --no-site-packages | 0.066568 | 0 | 0 | 4,495 |
2,767,854 | 2010-05-04T18:14:00.000 | 2 | 0 | 1 | 0 | python,lua,eval | 2,768,130 | 3 | false | 0 | 0 | From your comments, it appears you a interested in a secure way of executing untrusted code.
Redifining python builtins, as you suggested in a comment, is a horrible way to secure code.
What you want is sandboxing, there are solutions for python, but I wouldn't recommend them. You would be much better of using Jython or IronPython, because the JVM and .NET clr, were designed with sandboxing in mind.
I personally believe that in most cases, if you need to execute untrusted code, then you are putting too much or not enough trust in your users. | 2 | 2 | 0 | I'm looking into using Lua in a web project. I can't seem to find any way of directly parsing in pure python and running Lua code in Python.
Does anyone know how to do this?
Joe | Lua parser in python | 0.132549 | 0 | 1 | 3,999 |
2,767,854 | 2010-05-04T18:14:00.000 | 1 | 0 | 1 | 0 | python,lua,eval | 18,090,375 | 3 | false | 0 | 0 | @the_drow
From Lua's web site:
Lua is a fast language engine with small footprint that you can embed
easily into your application. Lua has a simple and well documented API
that allows strong integration with code written in other languages.
It is easy to extend Lua with libraries written in other languages. It
is also easy to extend programs written in other languages with Lua.
Lua has been used to extend programs written not only in C and C++, but also in Java, C#, Smalltalk, Fortran, Ada, Erlang, and even in
other scripting languages, such as Perl and Ruby.
@Joe Simpson
Check out Lunatic Python, it might have what you want. I know it's an old question, but other people might be looking for this answer, as well. It's a good question that deserves a good answer. | 2 | 2 | 0 | I'm looking into using Lua in a web project. I can't seem to find any way of directly parsing in pure python and running Lua code in Python.
Does anyone know how to do this?
Joe | Lua parser in python | 0.066568 | 0 | 1 | 3,999 |
2,769,061 | 2010-05-04T21:21:00.000 | 0 | 0 | 1 | 0 | python | 2,769,073 | 12 | false | 0 | 0 | You cannot "erase" from a file in-place unless you need to erase the end. Either be content with an overwrite of an "empty" value, or read the parts of the file you care about and write it to another file. | 4 | 210 | 0 | I have text file which I want to erase in Python. How do I do that? | How to erase the file contents of text file in Python? | 0 | 0 | 0 | 414,656 |
2,769,061 | 2010-05-04T21:21:00.000 | 0 | 0 | 1 | 0 | python | 2,769,069 | 12 | false | 0 | 0 | Since text files are sequential, you can't directly erase data on them. Your options are:
The most common way is to create a new file. Read from the original file and write everything on the new file, except the part you want to erase. When all the file has been written, delete the old file and rename the new file so it has the original name.
You can also truncate and rewrite the entire file from the point you want to change onwards. Seek to point you want to change, and read the rest of file to memory. Seek back to the same point, truncate the file, and write back the contents without the part you want to erase.
Another simple option is to overwrite the data with another data of same length. For that, seek to the exact position and write the new data. The limitation is that it must have exact same length.
Look at the seek/truncate function/method to implement any of the ideas above. Both Python and C have those functions. | 4 | 210 | 0 | I have text file which I want to erase in Python. How do I do that? | How to erase the file contents of text file in Python? | 0 | 0 | 0 | 414,656 |
2,769,061 | 2010-05-04T21:21:00.000 | 0 | 0 | 1 | 0 | python | 2,769,093 | 12 | false | 0 | 0 | Assigning the file pointer to null inside your program will just get rid of that reference to the file. The file's still there. I think the remove() function in the c stdio.h is what you're looking for there. Not sure about Python. | 4 | 210 | 0 | I have text file which I want to erase in Python. How do I do that? | How to erase the file contents of text file in Python? | 0 | 0 | 0 | 414,656 |
2,769,061 | 2010-05-04T21:21:00.000 | 13 | 0 | 1 | 0 | python | 45,281,654 | 12 | false | 0 | 0 | When using with open("myfile.txt", "r+") as my_file:, I get strange zeros in myfile.txt, especially since I am reading the file first. For it to work, I had to first change the pointer of my_file to the beginning of the file with my_file.seek(0). Then I could do my_file.truncate() to clear the file. | 4 | 210 | 0 | I have text file which I want to erase in Python. How do I do that? | How to erase the file contents of text file in Python? | 1 | 0 | 0 | 414,656 |
2,769,910 | 2010-05-05T00:48:00.000 | 0 | 0 | 0 | 1 | python,macos,setuptools,sourceforge-appscript | 9,352,639 | 2 | false | 0 | 0 | I don't think the solution proposed is sufficient in many cases, as (for example) I already have the tools in /usr/bin and get the same error.
The problem is that gcc is being invoked with an -arch ppc flag, which generally is not supported any longer.
You need to (a)
set ARCHFLAGS in the shell environment so that is it
something like '-arch i386 -arch x86_64'
or for (b) for a permanent fix:
edit
/System/Library/Frameworks/Python.framework/Versions/Current/lib/python*/distutils/sysconfig.py
to change
archflags = '-arch i386 -arch ppc -arch x86_64'
or be
archflags = '-arch i386 -arch x86_64' | 2 | 2 | 0 | I am having some trouble getting appscript installed on OS/X 10.6.3 / Python 2.6.1. When I issue
sudo easy_install appscript
I get "unable to execute gcc-4.2: No such file or directory". Even when I do export CC=/Developer/usr/bin/gcc-4.2 (a valid gcc-4.2 executable), easy_install barks.
What could be the issue?
Disclaimer: OS/X newbie at the helm... | appscript on OSX 10.6.3 / Python 2.6.1 | 0 | 0 | 0 | 660 |
2,769,910 | 2010-05-05T00:48:00.000 | 4 | 0 | 0 | 1 | python,macos,setuptools,sourceforge-appscript | 2,770,010 | 2 | true | 0 | 0 | Rerun the Xcode installer and check "UNIX Development" - it will put compilers in /usr/bin in addition to /Developer. | 2 | 2 | 0 | I am having some trouble getting appscript installed on OS/X 10.6.3 / Python 2.6.1. When I issue
sudo easy_install appscript
I get "unable to execute gcc-4.2: No such file or directory". Even when I do export CC=/Developer/usr/bin/gcc-4.2 (a valid gcc-4.2 executable), easy_install barks.
What could be the issue?
Disclaimer: OS/X newbie at the helm... | appscript on OSX 10.6.3 / Python 2.6.1 | 1.2 | 0 | 0 | 660 |
2,770,030 | 2010-05-05T01:24:00.000 | 1 | 1 | 0 | 0 | python,file,r,performance | 2,770,393 | 6 | false | 0 | 0 | what do you mean by "file manipulation?" are you talking about moving files around, deleting, copying, etc., in which case i would use a shell, e.g., bash, etc. if you're talking about reading in the data, performing calculations, perhaps writing out a new file, etc., then you could probably use Python or R. unless maintenance is an issue, i would just leave it as R and find other fish to fry as you're not going to see enough of a speedup to justify your time and effort in porting that code. | 5 | 3 | 1 | I have 4 reasonably complex r scripts that are used to manipulate csv and xml files. These were created by another department where they work exclusively in r.
My understanding is that while r is very fast when dealing with data, it's not really optimised for file manipulation. Can I expect to get significant speed increases by converting these scripts to python? Or is this something of a waste of time? | R or Python for file manipulation | 0.033321 | 0 | 0 | 2,365 |
2,770,030 | 2010-05-05T01:24:00.000 | 1 | 1 | 0 | 0 | python,file,r,performance | 2,770,138 | 6 | false | 0 | 0 | Know where the time is being spent. If your R scripts are bottlenecked on disk IO (and that is very possible in this case), then you could rewrite them in hand-optimized assembly and be no faster. As always with optimization, if you don't measure first, you're just pissing into the wind. If they're not bottlenecked on disk IO, you would likely see more benefit from improving the algorithm than changing the language. | 5 | 3 | 1 | I have 4 reasonably complex r scripts that are used to manipulate csv and xml files. These were created by another department where they work exclusively in r.
My understanding is that while r is very fast when dealing with data, it's not really optimised for file manipulation. Can I expect to get significant speed increases by converting these scripts to python? Or is this something of a waste of time? | R or Python for file manipulation | 0.033321 | 0 | 0 | 2,365 |
2,770,030 | 2010-05-05T01:24:00.000 | 0 | 1 | 0 | 0 | python,file,r,performance | 2,770,071 | 6 | false | 0 | 0 | My guess is that you probably won't see much of a speed-up in time. When comparing high-level languages, overhead in the language is typically not to blame for performance problems. Typically, the problem is your algorithm.
I'm not very familiar with R, but you may find speed-ups by reading larger chunks of data into memory at once vs smaller chunks (less system calls). If R doesn't have the ability to change something like this, you will probably find that python can be much faster simply because of this ability. | 5 | 3 | 1 | I have 4 reasonably complex r scripts that are used to manipulate csv and xml files. These were created by another department where they work exclusively in r.
My understanding is that while r is very fast when dealing with data, it's not really optimised for file manipulation. Can I expect to get significant speed increases by converting these scripts to python? Or is this something of a waste of time? | R or Python for file manipulation | 0 | 0 | 0 | 2,365 |
2,770,030 | 2010-05-05T01:24:00.000 | 0 | 1 | 0 | 0 | python,file,r,performance | 2,771,903 | 6 | false | 0 | 0 | R data manipulation has rules for it to be fast. The basics are:
vectorize
use data.frames as little as possible (for example, in the end)
Search for R time optimization and profiling and you will find many resources to help you. | 5 | 3 | 1 | I have 4 reasonably complex r scripts that are used to manipulate csv and xml files. These were created by another department where they work exclusively in r.
My understanding is that while r is very fast when dealing with data, it's not really optimised for file manipulation. Can I expect to get significant speed increases by converting these scripts to python? Or is this something of a waste of time? | R or Python for file manipulation | 0 | 0 | 0 | 2,365 |
2,770,030 | 2010-05-05T01:24:00.000 | 10 | 1 | 0 | 0 | python,file,r,performance | 2,770,354 | 6 | true | 0 | 0 | I write in both R and Python regularly. I find Python modules for writing, reading and parsing information easier to use, maintain and update. Little niceties like the way python lets you deal with lists of items over R's indexing make things much easier to read.
I highly doubt you will gain any significant speed-up by switching the language. If you are becoming the new "maintainer" of these scripts and you find Python easier to understand and extend, then I'd say go for it.
Computer time is cheap ... programmer time is expensive. If you have other things to do then I'd just limp along with what you've got until you have a free day to putz with them.
Hope that helps. | 5 | 3 | 1 | I have 4 reasonably complex r scripts that are used to manipulate csv and xml files. These were created by another department where they work exclusively in r.
My understanding is that while r is very fast when dealing with data, it's not really optimised for file manipulation. Can I expect to get significant speed increases by converting these scripts to python? Or is this something of a waste of time? | R or Python for file manipulation | 1.2 | 0 | 0 | 2,365 |
2,770,356 | 2010-05-05T03:02:00.000 | 1 | 0 | 0 | 0 | python,arcgis,raster | 2,785,460 | 3 | false | 0 | 0 | You need a library that can read your raster. I am not sure how to do that in Python but you could look at geotools (especially with some of the new raster library integration) if you want to program in Java. If you are good with C I would reccomend using something like GDAL.
If you want to look at a desktop tool you could look at extending QGIS with python to do the operation above.
If I remember correctly, the Raster extension to PostGIS may support clipping rasters based upon vectors. This means you would need to create your circles to features in the DB and then import your raster but then you might be able to use SQL to extract your values.
If you are really just a text file with numbers in a grid then I would go with the suggestions above. | 1 | 4 | 1 | I have a raster file (basically 2D array) with close to a million points. I am trying to extract a circle from the raster (and all the points that lie within the circle). Using ArcGIS is exceedingly slow for this. Can anyone suggest any image processing library that is both easy to learn and powerful and quick enough for something like this?
Thanks! | Extract points within a shape from a raster | 0.066568 | 0 | 0 | 3,334 |
2,770,426 | 2010-05-05T03:33:00.000 | 0 | 1 | 0 | 0 | php,python | 4,735,025 | 4 | false | 1 | 0 | I just started Python for web myself. I also came from a PHP background and felt that PHP is fine when it comes to making regular stuff like forums, blogs and stuff like that. Sadly though I didn't like PHP when it came to create more complex systems.
I looked at a few of the different frameworks out there and came to the conclusion if I want to use a Framework that applies as much to web as to client and server side programming Turbogears2 would suit med best.
Seems like one of the "newer" frameworks and looks like they got a solid community that will keep they going for years to come.
Oh, lol this post sounds like and ad. Sorry ;)
Anyway, I like to use webpages that you can work with the hardware on the server, which means CGI/WSGI or just Turbogears :) | 1 | 2 | 0 | I'm looking for a nice tutorial or framework for developing Python written web applications.
I've done lots in PHP, but very little in Python or Ruby and figured I'd start with the first one alphabetically. | Beginning python for the web | 0 | 0 | 0 | 617 |
2,771,561 | 2010-05-05T08:25:00.000 | 1 | 1 | 1 | 0 | python,profiling | 2,771,660 | 2 | false | 0 | 0 | A CPU second is one second that your process is actually scheduled on the CPU. It can be significantly smaller than than the elapsed real time in case of a busy system, and it can be higher in case of your process running on multiple cores (if the count is per-process, not per-thread).
It should never be negative, though... | 2 | 4 | 0 | Hey, I'm totally behind this topic.
Yesterday I was doing profiling using Python profiler module for some script I'm working on, and the unit for time spent was a 'CPU second'. Can anyone remind me with the definition of it?
For example for some profiling I got: 200.750 CPU seconds. What does that supposed to mean? At other case and for time consuming process I got: -347.977 CPU seconds, a negative number!
Is there anyway I can convert that time, to calendar time?
Cheers, | Python profiler and CPU seconds | 0.099668 | 0 | 0 | 1,333 |
2,771,561 | 2010-05-05T08:25:00.000 | 8 | 1 | 1 | 0 | python,profiling | 2,771,828 | 2 | true | 0 | 0 | Roughly speaking, a CPU time of, say, 200.75 seconds means that if only one processor worked on the task and that processor were working on it all the time, it would have taken 200.75 seconds. CPU time can be contrasted with wall clock time, which means the actual time elapsed from the start of the task to the end of the task on a clock hanging on the wall of your room.
The two are not interchangeable and there is no way to convert one to the other unless you know exactly how your task was scheduled and distributed among the CPU cores of your system. The CPU time can be less than the wall clock time if the task was distributed among multiple CPU cores, and it can be more if the system was under a heavy load and your task was interrupted temporarily by other tasks. | 2 | 4 | 0 | Hey, I'm totally behind this topic.
Yesterday I was doing profiling using Python profiler module for some script I'm working on, and the unit for time spent was a 'CPU second'. Can anyone remind me with the definition of it?
For example for some profiling I got: 200.750 CPU seconds. What does that supposed to mean? At other case and for time consuming process I got: -347.977 CPU seconds, a negative number!
Is there anyway I can convert that time, to calendar time?
Cheers, | Python profiler and CPU seconds | 1.2 | 0 | 0 | 1,333 |
2,774,006 | 2010-05-05T14:19:00.000 | 1 | 0 | 0 | 0 | python,windows,internet-explorer,url | 2,774,159 | 2 | false | 0 | 0 | Doing this at the machine level is a weak solution, it would be pretty easy for a technically inclined user to bypass.
Even with a server side proxy it will be very easy to bypass unless you firewall normal http traffic, at a bare minimum block ports 80, 443.
You could program a proxy in python as Alex suggested, but this is a pretty common problem and there are plenty of off the shelf solutions.
That being said, I think that restricting web access will do nothing but aggravate your users. | 1 | 1 | 0 | I need to be able to block the urls that are stored in a text file on the hard disk using Python. If the url the user tries to visit is in the file, it redirects them to another page instead. How is this done? | Internet Explorer URL blocking with Python? | 0.099668 | 0 | 1 | 957 |
2,774,723 | 2010-05-05T15:45:00.000 | 4 | 0 | 0 | 0 | python,django,google-app-engine,gis | 2,775,206 | 3 | true | 1 | 0 | No. You can't use Django models on App Engine, and therefore, can't use anything else that uses them, such as django.contrib.gis. | 2 | 4 | 0 | Can I use GeoDjango with GAE / BigTable? | Can I use django.contrib.gis on GAE? | 1.2 | 0 | 0 | 523 |
2,774,723 | 2010-05-05T15:45:00.000 | 5 | 0 | 0 | 0 | python,django,google-app-engine,gis | 2,775,406 | 3 | false | 1 | 0 | Another limitation is that the GEOS and GDAL libs aren't available on App Engine. | 2 | 4 | 0 | Can I use GeoDjango with GAE / BigTable? | Can I use django.contrib.gis on GAE? | 0.321513 | 0 | 0 | 523 |
2,775,095 | 2010-05-05T16:36:00.000 | 0 | 0 | 0 | 1 | python,mysql,eclipse,pydev,mysql-python | 23,798,598 | 3 | false | 0 | 0 | If the connector works in the IDLE but not in PyDev. Open Eclipse preferences, open PyDev directory and go to interpreter screen. Remove the interpreter and add it again from the location on your computer (Usually C drive). Close and reload Eclipse and now it should work. | 2 | 2 | 0 | I am trying to access a MySQL database with python through Pydev Eclipse. I have installed the necessary files to access MysQL from python and I can access the database only when I write code in Python IDLE environment and run it from command prompt. However I am not able to run my applications from Pydev.
when I use this "import MysqlDB" i get an error, but in IDLE no errors and my code runs very smoothly.
Does anyone know were the problem is?
Thanks | Using MySQL in Pydev Eclipse | 0 | 1 | 0 | 6,768 |
2,775,095 | 2010-05-05T16:36:00.000 | 0 | 0 | 0 | 1 | python,mysql,eclipse,pydev,mysql-python | 70,125,088 | 3 | false | 0 | 0 | Posting Answer in case URL changed in future
From Eclipse, choose Window / Preferences / PyDev / Interpreters / Python Interpreter, click on Manage with pip and enter the command:
install mysql-connector-python | 2 | 2 | 0 | I am trying to access a MySQL database with python through Pydev Eclipse. I have installed the necessary files to access MysQL from python and I can access the database only when I write code in Python IDLE environment and run it from command prompt. However I am not able to run my applications from Pydev.
when I use this "import MysqlDB" i get an error, but in IDLE no errors and my code runs very smoothly.
Does anyone know were the problem is?
Thanks | Using MySQL in Pydev Eclipse | 0 | 1 | 0 | 6,768 |
2,775,213 | 2010-05-05T16:54:00.000 | 1 | 0 | 1 | 0 | python,linux | 2,775,260 | 5 | false | 0 | 0 | For which version of Python will run when you invoke the python command you will have to manually change the symlink that /usr/bin/python points to, but that won't change what the packaging system considers the "default version of Python" and means you will still have to install version-specific libraries if they are different for a specific version. Luckily, those packages have an easy naming convention, instead of just python-<foo> they are python2.4-<foo> and installing those will put them in the right path (specifically the right site-packages directory).
EDIT: apparently python isn't managed by the alternatives system, silly Debian/Ubuntu | 2 | 2 | 0 | I came from a Windows background whern it comes to development environments. I'm used to run .exe's from everything I need to run and just forget.
I usually code in php, javascript, css, html and python.
Now, I have to use Linux at my work, in a non changeable Ubuntu 8.04, with permissions to upgrade my system using company's repositories only.
I need to install Python 2.4.3 to start coding in an old legacy system. I had Python 2.5. I downloaded Python 2.4.3 tarballs, ran ./configure make and such. Everything worked out, but now the "default" installation is my system is Python2.4 instead of of Python2.5.
I want help from you to change it back, and if possible, some material to read about symlinks, multiple Python installations, virtualenvs and such: everything I need to know before installing/upgrading Python modules. I installed for example the ElementTree package and don't even know in which Python installation it was installed.
Thanks in advance! | Help with Python structure in *nixes | 0.039979 | 0 | 0 | 175 |
2,775,213 | 2010-05-05T16:54:00.000 | 2 | 0 | 1 | 0 | python,linux | 2,775,391 | 5 | false | 0 | 0 | You may have installed Python 2.4 in /usr/local/bin, which, in turn, may come in your $PATH before /usr/bin where 2.5 lives. There are various possible remediations, if that is the case: simplest is probably to rm the link named /usr/local/bin/python (leaving only the "system" one named /usr/bin/python). You will then have to use explicitly python2.4 to invoke the 2.4 installation, while just python will go to the system-installed Python 2.5 installation. | 2 | 2 | 0 | I came from a Windows background whern it comes to development environments. I'm used to run .exe's from everything I need to run and just forget.
I usually code in php, javascript, css, html and python.
Now, I have to use Linux at my work, in a non changeable Ubuntu 8.04, with permissions to upgrade my system using company's repositories only.
I need to install Python 2.4.3 to start coding in an old legacy system. I had Python 2.5. I downloaded Python 2.4.3 tarballs, ran ./configure make and such. Everything worked out, but now the "default" installation is my system is Python2.4 instead of of Python2.5.
I want help from you to change it back, and if possible, some material to read about symlinks, multiple Python installations, virtualenvs and such: everything I need to know before installing/upgrading Python modules. I installed for example the ElementTree package and don't even know in which Python installation it was installed.
Thanks in advance! | Help with Python structure in *nixes | 0.07983 | 0 | 0 | 175 |
2,776,311 | 2010-05-05T19:52:00.000 | 0 | 0 | 1 | 0 | python,algorithm,date,timezone | 2,776,395 | 5 | false | 0 | 0 | Try out something like this.
Select * from alerts where
date in (GetDate(), GetDate()+2, GetDATE()+5, GETDATE()+7)
and date-GetDate() =alertFrequency
Send the alerts to all the results of the above query | 2 | 3 | 0 | A user can set a day alert for a birthday. (We do not care about the year of birth)
He also picks if he wants to be alerted 0, 1, 2, ou 7 days (Delta) before the D day.
Users have a timezone setting.
I want the server to send the alerts at 8 am on the the D day - deleta +- user timezone
Example:
12 jun, with "alert me 3 days before" will give 9 of Jun.
My idea was to have a trigger_datetime extra field saved on the 'recurrent event' object.
Like this a cron Job running every hour on my server will just check for all events matching irs current time hour, day and month and send to the alert.
The problem from a year to the next the trigger_date could change !
If the alert is set on 1st of March, with a one day delay that could be either 28 or 29 of February ..
Maybe i should not use the trigger date trick and use some other kind of scheme.
All plans are welcome. | Recurrent yearly date alert in Python | 0 | 0 | 0 | 1,606 |
2,776,311 | 2010-05-05T19:52:00.000 | 0 | 0 | 1 | 0 | python,algorithm,date,timezone | 2,776,366 | 5 | false | 0 | 0 | You can do it in two parts.
Cron Job that triggers the application hourly,halfhourly or some other suitable frequency.
The Application checks if its time for any alerts to be triggered. Adds those alerts to a sending list. Sends email alerts to those customers. | 2 | 3 | 0 | A user can set a day alert for a birthday. (We do not care about the year of birth)
He also picks if he wants to be alerted 0, 1, 2, ou 7 days (Delta) before the D day.
Users have a timezone setting.
I want the server to send the alerts at 8 am on the the D day - deleta +- user timezone
Example:
12 jun, with "alert me 3 days before" will give 9 of Jun.
My idea was to have a trigger_datetime extra field saved on the 'recurrent event' object.
Like this a cron Job running every hour on my server will just check for all events matching irs current time hour, day and month and send to the alert.
The problem from a year to the next the trigger_date could change !
If the alert is set on 1st of March, with a one day delay that could be either 28 or 29 of February ..
Maybe i should not use the trigger date trick and use some other kind of scheme.
All plans are welcome. | Recurrent yearly date alert in Python | 0 | 0 | 0 | 1,606 |
2,776,663 | 2010-05-05T20:48:00.000 | 0 | 0 | 1 | 0 | python | 2,776,947 | 2 | true | 0 | 0 | i found out how to do it. basically myobject.membername1.membername2 | 1 | 1 | 0 | I'm trying to find information on different ways to traverse an object tree in python.
I don't know much about the language in general yet, so any suggestions/techniques would be welcome.
Thanks so much
jml | traversing an object tree | 1.2 | 0 | 0 | 488 |
2,776,721 | 2010-05-05T20:57:00.000 | 1 | 1 | 1 | 0 | ironpython,ironruby,ironpython-studio | 2,789,483 | 3 | false | 1 | 0 | Shortly the same support for IronRuby is arriving to visual studio. It will take maybe another couple of months but then it will get there. They first needed to get the language implementation right. | 2 | 0 | 0 | I've been using Ruby as my main scripting language for years but switched to .NET several years ago. I'd like to continue using Ruby (primarily for testing) BUT the toolset for IronRuby is really nonexistent. Why?
In Python, meanwhile, there are project templates and full intellisense support. Why isn't there something like that for IronRuby? The only thing I've been able to find on it is "there are no plans for VS integration at this time." Why??? | Why doesn't IronRuby have the same tools that IronPython does? | 0.066568 | 0 | 0 | 580 |
2,776,721 | 2010-05-05T20:57:00.000 | 1 | 1 | 1 | 0 | ironpython,ironruby,ironpython-studio | 2,778,756 | 3 | false | 1 | 0 | IronRuby has been out for 4 weeks, IronPython for 4 years. Developing an IDE takes months, if not years. When exactly where they supposed to squeeze that in?
Also, I believe the IronRuby team is smaller than the IronPython team.
There actually is a Ruby plugin for Visual Studio produced by SapphireSteel. It's called Ruby in Steel. Unfortunately, they currently only support MRI, YARV and JRuby. They did have IronRuby support at one point, but they removed it, because a) none of their customers actually used it, b) IronRuby was still changing faster than they could adapt and c) some of the IronRuby developers announced that Microsoft is considering developing IronRuby support for Visual Studio in the future and SapphireSteel didn't see much business sense in trying to compete with Microsoft.
Also, Visual Studio is not the only IDE on the planet. MonoDevelop has an open bug for IronRuby support, for example. And I'm pretty confident that it wouldn't be too hard to add IronRuby support to NetBeans: it already supports JRuby, MRI and YARV. | 2 | 0 | 0 | I've been using Ruby as my main scripting language for years but switched to .NET several years ago. I'd like to continue using Ruby (primarily for testing) BUT the toolset for IronRuby is really nonexistent. Why?
In Python, meanwhile, there are project templates and full intellisense support. Why isn't there something like that for IronRuby? The only thing I've been able to find on it is "there are no plans for VS integration at this time." Why??? | Why doesn't IronRuby have the same tools that IronPython does? | 0.066568 | 0 | 0 | 580 |
2,776,829 | 2010-05-05T21:14:00.000 | 12 | 0 | 1 | 0 | python,iterator,generator | 48,086,537 | 13 | false | 0 | 0 | Previous answers missed this addition: a generator has a close method, while typical iterators don’t. The close method triggers a StopIteration exception in the generator, which may be caught in a finally clause in that iterator, to get a chance to run some clean‑up. This abstraction makes it most usable in the large than simple iterators. One can close a generator as one could close a file, without having to bother about what’s underneath.
That said, my personal answer to the first question would be: iteratable has an __iter__ method only, typical iterators have a __next__ method only, generators has both an __iter__ and a __next__ and an additional close.
For the second question, my personal answer would be: in a public interface, I tend to favor generators a lot, since it’s more resilient: the close method an a greater composability with yield from. Locally, I may use iterators, but only if it’s a flat and simple structure (iterators does not compose easily) and if there are reasons to believe the sequence is rather short especially if it may be stopped before it reach the end. I tend to look at iterators as a low level primitive, except as literals.
For control flow matters, generators are an as much important concept as promises: both are abstract and composable. | 3 | 710 | 0 | What is the difference between iterators and generators? Some examples for when you would use each case would be helpful. | Difference between Python's Generators and Iterators | 1 | 0 | 0 | 212,522 |
2,776,829 | 2010-05-05T21:14:00.000 | 27 | 0 | 1 | 0 | python,iterator,generator | 46,126,307 | 13 | false | 0 | 0 | Everybody has a really nice and verbose answer with examples and I really appreciate it. I just wanted to give a short few lines answer for people who are still not quite clear conceptually:
If you create your own iterator, it is a little bit involved - you have
to create a class and at least implement the iter and the next methods. But what if you don't want to go through this hassle and want to quickly create an iterator. Fortunately, Python provides a short-cut way to defining an iterator. All you need to do is define a function with at least 1 call to yield and now when you call that function it will return "something" which will act like an iterator (you can call next method and use it in a for loop). This something has a name in Python called Generator
Hope that clarifies a bit. | 3 | 710 | 0 | What is the difference between iterators and generators? Some examples for when you would use each case would be helpful. | Difference between Python's Generators and Iterators | 1 | 0 | 0 | 212,522 |
2,776,829 | 2010-05-05T21:14:00.000 | 3 | 0 | 1 | 0 | python,iterator,generator | 70,071,263 | 13 | false | 0 | 0 | This thread covers in many details all the differences between the two, but wanted to add something on the conceptual difference between the two:
[...] an iterator as defined in the GoF book retrieves items from a collection, while a generator can produce items “out of thin air”. That’s why the Fibonacci sequence generator is a common example: an infinite series of numbers cannot be stored in a collection.
Ramalho, Luciano. Fluent Python (p. 415). O'Reilly Media. Kindle Edition.
Sure, it does not cover all the aspects but I think it gives a good notion when one can be useful. | 3 | 710 | 0 | What is the difference between iterators and generators? Some examples for when you would use each case would be helpful. | Difference between Python's Generators and Iterators | 0.046121 | 0 | 0 | 212,522 |
2,777,366 | 2010-05-05T23:05:00.000 | 0 | 0 | 1 | 0 | python,operators,int,boolean | 2,777,617 | 6 | false | 0 | 0 | No, you can't. When Guido unified types and classes, he found a way to override the behavior of built-in types (due to the way he implemented things), but he declared it a bug and plugged the loophole. Changing the behavior of built-in types (except for your example - importing division from future, which is there for a good reason) is forbidden.
Sorry, but I can't find the mailing list post. I remember it though, as it was quite interesting. | 3 | 4 | 0 | Is there any way to have Python operators line "==" and ">" return ints instead of bools. I know that I could use the int function (int(1 == 1)) or add 0 ((1 == 1) + 0) but I was wondering if there was an easy way to do it. Like when you want division to return floats you could type from __future__ import division. Is there any way to do this with operators returning ints? Or could I make a class extending __future__._Feature that would do what I want? | Python operators returning ints | 0 | 0 | 0 | 192 |
2,777,366 | 2010-05-05T23:05:00.000 | 0 | 0 | 1 | 0 | python,operators,int,boolean | 2,777,457 | 6 | false | 0 | 0 | Cast your bool to an int?
>>> int(True)
1
>>> int(False)
0
Or cast that to a str?
>>> str(int(True))
'1'
>>> str(int(False))
'0' | 3 | 4 | 0 | Is there any way to have Python operators line "==" and ">" return ints instead of bools. I know that I could use the int function (int(1 == 1)) or add 0 ((1 == 1) + 0) but I was wondering if there was an easy way to do it. Like when you want division to return floats you could type from __future__ import division. Is there any way to do this with operators returning ints? Or could I make a class extending __future__._Feature that would do what I want? | Python operators returning ints | 0 | 0 | 0 | 192 |
2,777,366 | 2010-05-05T23:05:00.000 | 3 | 0 | 1 | 0 | python,operators,int,boolean | 2,777,380 | 6 | false | 0 | 0 | You cant override the built-in comparison functions. In some sense the comparison operators are already returning int. bool is a subclass of int, so you can do anything to it that you can do to a int. The question then becomes why would you want to have comparisons return int objects, not bool objects? | 3 | 4 | 0 | Is there any way to have Python operators line "==" and ">" return ints instead of bools. I know that I could use the int function (int(1 == 1)) or add 0 ((1 == 1) + 0) but I was wondering if there was an easy way to do it. Like when you want division to return floats you could type from __future__ import division. Is there any way to do this with operators returning ints? Or could I make a class extending __future__._Feature that would do what I want? | Python operators returning ints | 0.099668 | 0 | 0 | 192 |
2,777,919 | 2010-05-06T01:41:00.000 | 1 | 0 | 0 | 0 | python,html,editor | 2,778,024 | 2 | true | 0 | 1 | To embed FCKeditor (or maybe better the current CKeditor?), you basically need to embed a full-fledged browser (with Javascript) -- I believe wxPython may currently be the best bet for that, as I hear it has wxIE for Windows and wxWebKitCtrl for the Mac (I don't know if old summer-of-code ideas about making something suitable for Linux ever panned out, though). Most "HTML viewer" widgets, in most GUIs, don't support Javascript, and that's a must for (F?)CKeditor. | 2 | 0 | 0 | I have a python application which need a gui HTML editor, I know FCKeditor is nice, so how to embed the FCKeditor in a python desktop app? | Embed FCKeditor in python app | 1.2 | 0 | 0 | 340 |
2,777,919 | 2010-05-06T01:41:00.000 | 0 | 0 | 0 | 0 | python,html,editor | 2,778,087 | 2 | false | 0 | 1 | In order of difficulty:
If you just need to support Windows, you can embed IE in wx - see the docs and demos.
wxWebKit is looking a bit more mature, but it's still in development.
You could just use the web-browser using webbrowser.open(url). Things will be very crude, and interaction will be a pain.
A fourth option - you could try out pyjamas for your whole GUI, then run it all in a web-browser. | 2 | 0 | 0 | I have a python application which need a gui HTML editor, I know FCKeditor is nice, so how to embed the FCKeditor in a python desktop app? | Embed FCKeditor in python app | 0 | 0 | 0 | 340 |
2,779,883 | 2010-05-06T09:15:00.000 | 0 | 0 | 0 | 0 | python,calendar,wxpython | 2,780,266 | 2 | true | 0 | 0 | Found it: you have to call cal.SetBusType(). | 1 | 0 | 0 | As per the title, is it possible to change the first day of the week (Monday instead of Sunday)? | Setting the first day of the week with the wx.lib.calendar.Calendar control? | 1.2 | 0 | 0 | 224 |
2,779,970 | 2010-05-06T09:29:00.000 | 2 | 0 | 1 | 0 | python,coding-style,kate | 2,780,096 | 3 | true | 1 | 0 | Ctrl-L simply refers to the character with ASCII code 12 (form feed, new page). It is called Ctrl-L only because some editors allow you to enter it with Ctrl-L. (For instance, in vim, one can type Ctrl-Q Ctrl-L to enter that character, and it also appears as ^L). In Kate, Ctrl-L is a shortcut for saving all files, so you cannot type it that way and I'm not sure there is any way of entering that character easily. | 2 | 3 | 0 | PEP 8 says:
Python accepts the control-L (i.e. ^L)
form feed character as whitespace;
Many tools treat these characters as
page separators, so you may use them
to separate pages of related sections
of your file
This look like a great idea for me, but in the text editor I use(kate) "control+L" is for save all files. Someone have any solution?
... or I'm losing something here? | page separator in Kate editor | 1.2 | 0 | 0 | 582 |
2,779,970 | 2010-05-06T09:29:00.000 | 2 | 0 | 1 | 0 | python,coding-style,kate | 18,721,903 | 3 | false | 1 | 0 | As a Kate developer, I unfortunately have to tell you that such control sequences are not supported. In fact, Kate often treats these files as binary files, since such characters are not human readable text. So in short: Try to avoid ^L. | 2 | 3 | 0 | PEP 8 says:
Python accepts the control-L (i.e. ^L)
form feed character as whitespace;
Many tools treat these characters as
page separators, so you may use them
to separate pages of related sections
of your file
This look like a great idea for me, but in the text editor I use(kate) "control+L" is for save all files. Someone have any solution?
... or I'm losing something here? | page separator in Kate editor | 0.132549 | 0 | 0 | 582 |
2,780,413 | 2010-05-06T10:43:00.000 | 7 | 0 | 1 | 0 | python,unicode,string | 2,780,474 | 2 | false | 0 | 0 | Calling str() on a unicode is the same as calling .encode(sys.getdefaultencoding()) on it. If the unicode contains characters that can't be encoded in the default encoding then it will throw a UnicodeEncodeError. The fix is to explicitly encode the unicode in a useful encoding, such as 'utf-8'. | 2 | 2 | 0 | for example the following:
str(u'לשום')
will throw an error.
how can i prevent these? | why in python giving to str func a unicode string will throw an exception? | 1 | 0 | 0 | 218 |
2,780,413 | 2010-05-06T10:43:00.000 | 0 | 0 | 1 | 0 | python,unicode,string | 2,780,957 | 2 | false | 0 | 0 | If you're running on Python 3, the u'' notation is a syntax error. Is this your problem? Because in Python <3, your code is absolutely correct, and since 'test' is plain ASCII there are no decoding issues. | 2 | 2 | 0 | for example the following:
str(u'לשום')
will throw an error.
how can i prevent these? | why in python giving to str func a unicode string will throw an exception? | 0 | 0 | 0 | 218 |
2,780,893 | 2010-05-06T12:03:00.000 | 1 | 0 | 0 | 0 | python,django,apache | 2,780,948 | 5 | false | 1 | 0 | Use python to rewrite the .htaccess automatically?
Use a database with users and use a Apache sessions to authenticate? | 1 | 2 | 0 | In my app users can upload files for other users.
To make the uploaded files accesible only for the addresse I need some kind of static files authentication system.
My idea, is to create the apache hosted directory for each user and to limit access to this derectory using .htaccess.
This means that each time new django user is created, I need to create a directory and the appropriate .htaccess file in it. I know I should do it using post_save signals on User model but I don't know how to create the .htaccess in the user's directory from python level. Can you help me with that?
Or perhaps you have better solution to my problem? | django authentication .htaccess static | 0.039979 | 0 | 0 | 1,305 |
2,782,229 | 2010-05-06T15:23:00.000 | 15 | 1 | 1 | 0 | python | 15,462,293 | 13 | false | 0 | 0 | Note: random.choice(string.hexdigits) is incorrect, because string.hexdigits returns 0123456789abcdefABCDEF (both lowercase and uppercase), so you will get a biased result, with the hex digit 'c' twice as likely to appear as the digit '7'. Instead, just use random.choice('0123456789abcdef'). | 1 | 112 | 0 | What is the most lightweight way to create a random string of 30 characters like the following?
ufhy3skj5nca0d2dfh9hwd2tbk9sw1
And an hexadecimal number of 30 digits like the followin?
8c6f78ac23b4a7b8c0182d7a89e9b1 | Most lightweight way to create a random string and a random hexadecimal number | 1 | 0 | 0 | 115,807 |
2,783,075 | 2010-05-06T17:22:00.000 | 2 | 0 | 0 | 0 | python,geometry,gis,geodjango | 2,783,174 | 1 | false | 0 | 1 | Pick any point inside the rectangle
Draw two lines through it parallel to the edges of the rectangle. Now you've divided your rectangle into four smaller ones. | 1 | 2 | 0 | I am working with geodjango and I want to breakup a 2D Rectangular Polygon into smaller ones.
My input is a big rectangle and I want to subdivide it in smaller rectangles. The sum of the smaller rectangles must be the original rectangle.
All subrectangles should be equal size.
How can I do that?
Thank you. | Break up a polygon into smaller ones | 0.379949 | 0 | 0 | 1,964 |
2,785,703 | 2010-05-07T01:52:00.000 | 0 | 0 | 0 | 0 | python,xml,minidom | 2,785,722 | 2 | false | 0 | 0 | Geez, never noticed that before. You're not kidding, node.value isn't mentioned anywhere. It is definitely being set in the code though under def __setitem__ in xml.dom.minidom.
Not sure what to say other than, it looks like you'll have to use that. | 1 | 3 | 0 | Getting attributes using minidom in Python, one uses the "attributes" property. e.g. node.attributes["id"].value
So if I have <a id="foo"></a>, that should give me "foo". node.attributes["id"] does not return the value of the named attribute, but an xml.dom.minidom.Attr instance.
But looking at the help for Attr, by doing help('xml.dom.minidom.Attr'), nowhere is this magic "value" property mentioned. I like to learn APIs by looking at the type hierarchy, instance methods etc. Where did this "value" property come from?? Why is it not listed in the Attr class' page? The only data descriptors mentioned are isId, localName and schemaType. Its also not inherited from any superclasses. Since I'm new to Python, would some of the Python gurus enlighten? | python xml.dom.minidom.Attr question | 0 | 0 | 1 | 10,689 |
2,785,755 | 2010-05-07T02:13:00.000 | 1 | 0 | 1 | 0 | python,regex | 2,785,773 | 17 | false | 0 | 0 | This regex will do that: (?:^|;)("(?:[^"]+|"")*"|[^;]*) | 1 | 71 | 0 | I need to split a string like this, on semicolons. But I don't want to split on semicolons that are inside of a string (' or "). I'm not parsing a file; just a simple string with no line breaks.
part 1;"this is ; part 2;";'this is ; part 3';part 4;this "is ; part" 5
Result should be:
part 1
"this is ; part 2;"
'this is ; part 3'
part 4
this "is ; part" 5
I suppose this can be done with a regex but if not; I'm open to another approach. | How to split but ignore separators in quoted strings, in python? | 0.011764 | 0 | 0 | 68,858 |
2,786,803 | 2010-05-07T07:03:00.000 | 0 | 1 | 0 | 0 | python,html,newline,genshi | 2,786,862 | 4 | false | 1 | 0 | Maybe use a <pre> tag. | 1 | 1 | 0 | I would like to know if is there any way to convert a plain unicode string to HTML in Genshi, so, for example, it renders newlines as <br/>.
I want this to render some text entered in a textarea.
Thanks in advance! | Print string as HTML | 0 | 0 | 0 | 764 |
2,788,927 | 2010-05-07T13:35:00.000 | 1 | 0 | 0 | 0 | python,gtk,pygtk,glade,gtkbuilder | 2,789,043 | 1 | true | 0 | 1 | Use checkbutton.get_active(). What's this got to do with GtkBuilder? | 1 | 0 | 0 | How do I find if a GTKBuilder Checkbutton is checked? | Python Glade GTKBuilder Checkbutton | 1.2 | 0 | 0 | 703 |
2,790,108 | 2010-05-07T16:32:00.000 | 3 | 0 | 1 | 1 | python,windows | 2,790,148 | 2 | false | 0 | 0 | Don't. There's nothing worse than two windows that think they deserve to be the one on top fighting it out. I've seen CPUs dragged to their knees by it. | 2 | 0 | 0 | How do I force my console window to be always on top with Python? | console window on top with Python? | 0.291313 | 0 | 0 | 717 |
2,790,108 | 2010-05-07T16:32:00.000 | 2 | 0 | 1 | 1 | python,windows | 2,790,211 | 2 | true | 0 | 0 | Unless you are using a console window written by yourself as a "real" window you can alter the state of, you'd have to talk to the window manager (be it Windows's or some of the Linux ones).
But I agree with Paul Tomblin. I think most window managers have that feature built in for users to activate it if they WANT it on top! | 2 | 0 | 0 | How do I force my console window to be always on top with Python? | console window on top with Python? | 1.2 | 0 | 0 | 717 |
2,791,683 | 2010-05-07T21:04:00.000 | 1 | 0 | 0 | 0 | python,facebook,oauth | 7,356,440 | 2 | false | 1 | 0 | If you only need to authenticate as one user, you can get an access token with the offline_access permission that will last forever and just bake that into the script. | 1 | 4 | 0 | I'm writing a (tabbed) application for Facebook that requires a background process to run on a server and, periodically, upload images to an album on this application's page.
What I'm trying to do is create a script that will:
a) authenticate me with the app
b) upload an image to a specific album
All of this entirely from the command line and completely with the new Graph API.
My problem right now is trying to locate the documentation that will allow me to get a token without a pop-up window of sorts.
Thoughts? | Can you authenticate Facebook Graph entirely from command line with Python? | 0.099668 | 0 | 1 | 1,483 |
2,791,946 | 2010-05-07T22:05:00.000 | 5 | 0 | 0 | 0 | python,http,exception,tcp | 2,792,030 | 1 | true | 0 | 0 | The httplib module doesn't use exceptions to convey HTTP responses, just genuine errors (invalid HTTP responses, broken headers, invalid status codes, prematurely broken connections, etc.) Most of the httplib.HTTPException subclasses just have an associated message string (stored in the args attribute), if even that. httplib.HTTPException itself may have an "errno" value as the first entry in args (when raised through httplib.FakeSocket) but it's not a HTTP error code.
The HTTP response codes are conveyed through the httplib.HTTPConnection object, though; the getresponse method will (usually) return a HTTPResponse instance with a status attribute set to the HTTP response code, and a reason attribute set to the text version of it. This includes error codes like 404 and 500. I say "usually" because you (or a library you use) can override httplib.HTTPConnection.response_class to return something else. | 1 | 2 | 0 | Does httplib.HTTPException have error codes? If so how do I get at them from the exception instance? Any help is appreciated. | python httplib httpexception error codes | 1.2 | 0 | 1 | 3,303 |
2,792,425 | 2010-05-08T00:27:00.000 | 0 | 0 | 1 | 0 | c#,python,actionscript-3 | 2,792,474 | 5 | true | 0 | 0 | To give a comparison of the two:
Action Script is useable only in Flash games (mostly run through web browser), which may be fun for some time, but it limits what you can do. On the other hand, it is probably the best way for developing web-based games.
C# and .NET allows you to write all sorts of different games (and is also more generally useful language in case you wanted to switch from game development to some other field, including web site development and various business applications). Regarding games, you can use it on:
Web based games (similar to Flash) using Silverlight
Desktop/XBox/Zune games using XNA Game Studio
iPhone games using MonoTouch (although there are some licensing issues recently)
By learning C#, you'll also learn .NET Framework (in general), which is (I think) a useful knowledge that you can benefit from in many situations (e.g. when looking for a job :-)) | 3 | 0 | 0 | I have a background in python and I'm looking for a new language. I am almost only intrested in making games.
I have come to 2 languages. C# and Action Script.
C# because Microsoft allows you to make Indie XBLA games programmed in C# ONLY.
Action Script so I can make flash games for new grounds and ect.
What do you think is better to learn in the long run? | Learn Actionscript 3.0+Flash Vs. C# | 1.2 | 0 | 0 | 1,520 |
2,792,425 | 2010-05-08T00:27:00.000 | 2 | 0 | 1 | 0 | c#,python,actionscript-3 | 2,792,612 | 5 | false | 0 | 0 | I have zero experience with C#, but I'll speak to AS3/Flash's #1 advantage:
For learning game development, Flash lets you make games very quickly, but more importantly lets you get feedback from a large number of users faster than any other environment (except possibly Ajax only). I started Flash programming a little over two years ago. In my first three months I learned AS3 and wrote a TD-style game that was eventually played by over a million people. During beta testing and after release I was getting constant feedback and tweaking the game mechanics and interface with multiple "releases" a day.
While not every game out there gets that much play, with Flash it is much easier to make something and have a large number of people actually play it and tell you what they like and what they don't. Learning how to make good games is harder than learning a different programming language. | 3 | 0 | 0 | I have a background in python and I'm looking for a new language. I am almost only intrested in making games.
I have come to 2 languages. C# and Action Script.
C# because Microsoft allows you to make Indie XBLA games programmed in C# ONLY.
Action Script so I can make flash games for new grounds and ect.
What do you think is better to learn in the long run? | Learn Actionscript 3.0+Flash Vs. C# | 0.07983 | 0 | 0 | 1,520 |
2,792,425 | 2010-05-08T00:27:00.000 | 2 | 0 | 1 | 0 | c#,python,actionscript-3 | 2,792,447 | 5 | false | 0 | 0 | I would say C#. You'll learn the basics and then be able to write games for the Desktop (XNA), XBox (XNA), Mobile Devices (XNA and XNA Touch for the iPhone), the Web (via Silverlight), etc.
Flash only gets you limited exposure to each. | 3 | 0 | 0 | I have a background in python and I'm looking for a new language. I am almost only intrested in making games.
I have come to 2 languages. C# and Action Script.
C# because Microsoft allows you to make Indie XBLA games programmed in C# ONLY.
Action Script so I can make flash games for new grounds and ect.
What do you think is better to learn in the long run? | Learn Actionscript 3.0+Flash Vs. C# | 0.07983 | 0 | 0 | 1,520 |
2,793,702 | 2010-05-08T10:28:00.000 | 1 | 0 | 1 | 0 | python,py2exe | 2,796,012 | 1 | true | 0 | 0 | I did it long ago, so I hope I remember correctly:
Set compressed to False, so py2exe won't create a Zip'd library file.
Set optimize to zero, so py2exe will write pyc files.
UPDATE: Ram Rachum is right, use the skip_archive option instead of compressed.
You won't be able to modify your main Python file, since it will be embedded into the main executable, so keep that to a minimum. Then you'll be able to replace the pyc files with your py files manually in your distribution as needed. No reason to replace the standard libraries, however, only your own code.
(It is not optimal for debugging, but I guess you want to fix some problem happening only to the release build of your software this way.)
Please let me know if it does not work and I'll try to help.
UPDATE:
I've just read the relevant parts of the py2exe source code. It seems that py2exe does not support it out of the box. So we've left with the option to touch its source code.
You can easily modify py2exe to support this mode. See the byte_compile function in build_exe.py. There's a call to the compile built-in function in it, which you can replace with a copy_file. Don't forget to modify the destination file name (dfile) to have the extension .py instead of .pyc or .pyo. I know that it is patchwork, but I don't see any other possibility to solve your problem.
You can also add a new py2exe option or introduce a new optimize value for this if you're curious. It would be an open-source contribution to py2exe, actually. ;) | 1 | 2 | 0 | Is there any way to make py2exe output .py source files instead of byte-compiled .pyc files in the library? | Making py2exe produce `.py` files | 1.2 | 0 | 0 | 726 |
2,793,789 | 2010-05-08T11:00:00.000 | 39 | 1 | 1 | 0 | python | 2,793,824 | 8 | false | 0 | 0 | Use os.makedirs to create the directory tree. | 1 | 89 | 0 | If a path such as b/c/ does not exist in ./a/b/c , shutil.copy("./blah.txt", "./a/b/c/blah.txt") will complain that the destination does not exist. What is the best way to create both the destination path and copy the file to this path? | create destination path for shutil.copy files | 1 | 0 | 0 | 114,233 |
2,794,362 | 2010-05-08T14:06:00.000 | 1 | 0 | 1 | 0 | python,datetime | 2,794,572 | 4 | true | 0 | 0 | Python itself does not handle sessions. Sessions are a concept that is handled by the web server. For example Apache can handle sessions. Python can access the sessions variables with mod_python, mod_wsgi, or through cgi. Furthermore, web frameworks built on top of these technologies (ex: Django) can access session variables. | 3 | 1 | 0 | I have a datetime.date variable in python.I need to pass it to a function do operations according to the date given and then increment the date for the next set of operations.The problem is I have to do the operations in diff pages and hence I need the date as a variable which can go from page to page. Can we do this in python.......
This is to be done in .py scripts and not any web related work........ | Does python have a session variable concept? | 1.2 | 0 | 0 | 936 |
2,794,362 | 2010-05-08T14:06:00.000 | 2 | 0 | 1 | 0 | python,datetime | 2,794,495 | 4 | false | 0 | 0 | You could build a global dict of "sessions" and update that dict when appropriate. | 3 | 1 | 0 | I have a datetime.date variable in python.I need to pass it to a function do operations according to the date given and then increment the date for the next set of operations.The problem is I have to do the operations in diff pages and hence I need the date as a variable which can go from page to page. Can we do this in python.......
This is to be done in .py scripts and not any web related work........ | Does python have a session variable concept? | 0.099668 | 0 | 0 | 936 |
2,794,362 | 2010-05-08T14:06:00.000 | 5 | 0 | 1 | 0 | python,datetime | 2,794,445 | 4 | false | 0 | 0 | Sessions have nothing to do with Python per se. See your web framework's documentation for how it handles sessions. | 3 | 1 | 0 | I have a datetime.date variable in python.I need to pass it to a function do operations according to the date given and then increment the date for the next set of operations.The problem is I have to do the operations in diff pages and hence I need the date as a variable which can go from page to page. Can we do this in python.......
This is to be done in .py scripts and not any web related work........ | Does python have a session variable concept? | 0.244919 | 0 | 0 | 936 |
2,794,829 | 2010-05-08T16:44:00.000 | 0 | 0 | 1 | 0 | python,concurrency,pylons,beaker | 2,794,890 | 2 | false | 0 | 0 | I just realized that this was a terrible question since locking a lock and saving it to the session takes two steps thus defeating the purpose of the lock's atomic actions. | 1 | 1 | 0 | There is a certain page on my website where I want to prevent the same user from visiting it twice in a row. To prevent this, I plan to create a Lock object (from Python's threading library). However, I would need to store that across sessions. Is there anything I should watch out for when trying to store a Lock object in a session (specifically a Beaker session)? | Are there any concerns I should have about storing a Python Lock object in a Beaker session? | 0 | 0 | 0 | 167 |
2,794,994 | 2010-05-08T17:30:00.000 | 0 | 1 | 1 | 0 | python,parallel-processing,rabbitmq | 3,437,797 | 2 | false | 0 | 0 | what about prefetching (QOS)? on small queueus I give the appearance of parallelism by declaring the queue, getting the number of messages currently available, attaching a consumer, consuming the messages and then closing it once the number of messages has been consumed. Closing the channel without acknowledging the messages makes the messages available to other consumers, poll the queue quickly enough and you could have a parallel-ish solution. | 2 | 2 | 0 | I'm having a problem where I have a queue set up in shared mode and multiple consumers bound to it. The issue is that it appears that rabbitmq is serializing the messages, that is, only one consumer at a time is able to run. I need this to be parallel, however, I can't seem to figure out how.
Each consumer is running in its own process. There are plenty of messages in the queue. I'm using py-amqplib to interface with RabbitMQ.
Any thoughts? | RabbitMQ serializing messages from queue with multiple consumers | 0 | 0 | 0 | 926 |
2,794,994 | 2010-05-08T17:30:00.000 | 0 | 1 | 1 | 0 | python,parallel-processing,rabbitmq | 6,284,649 | 2 | false | 0 | 0 | Refefer, the preferred AMQP model seems to be a queue-per-connected-consumer. You should create a "direct" exchange and agree upon a routing key that your consumers will all listen for. Then, each consumer that connects should create an exclusive, private, not-durable queue, and use queue_bind() to subscribe their queue to messages matching the public routing key on the exchange. Using this arrangement, my workers are getting to operate in parallel instead of having their operations serialized! | 2 | 2 | 0 | I'm having a problem where I have a queue set up in shared mode and multiple consumers bound to it. The issue is that it appears that rabbitmq is serializing the messages, that is, only one consumer at a time is able to run. I need this to be parallel, however, I can't seem to figure out how.
Each consumer is running in its own process. There are plenty of messages in the queue. I'm using py-amqplib to interface with RabbitMQ.
Any thoughts? | RabbitMQ serializing messages from queue with multiple consumers | 0 | 0 | 0 | 926 |
2,795,240 | 2010-05-08T18:54:00.000 | 2 | 1 | 0 | 0 | python,ironpython,version,detection | 2,795,246 | 4 | false | 0 | 0 | The "cli" (= Common Language Infrastructure = .NET = IronPython) is probably reliable.
As far as I know, you can access .NET libraries within IronPython, so you could try importing a .NET library, and catch the exception it throws when .NET is not available (as in CPython). | 1 | 15 | 0 | I need to write a module which will be used from both CPython and IronPython. What's the best way to detect IronPython, since I need a slightly different behaviour in that case?
I noticed that sys.platform is "win32" on CPython, but "cli" on IronPython.
Is there another preferred/standard way of detecting it? | Best way to detect IronPython | 0.099668 | 0 | 0 | 3,087 |
2,797,572 | 2010-05-09T12:06:00.000 | 4 | 1 | 0 | 0 | python,python-2.7,microphone | 2,797,821 | 2 | false | 0 | 0 | Microphones are analog devices, most api's probably couldn't even tell you if there is a microphone plugged in, your computer just reads data from one of your soundcards input channels.
What you probably want to know is if the input channels are turned on or off. Determining that is highly platform specific. | 1 | 1 | 0 | I want to see if there is a microphone active using Python.
How can I do it?
Thanks in advance! | How to see if there is one microphone active using python? | 0.379949 | 0 | 0 | 1,773 |
2,797,878 | 2010-05-09T14:12:00.000 | -1 | 0 | 0 | 0 | python,django,django-apps | 2,797,899 | 3 | false | 1 | 0 | Yeah, adding a context processor is the most recommended approach to achieve this. | 2 | 1 | 0 | Say I'm writing a Django app, and all the templates in the app require a certain variable.
The "classic" way to deal with this, afaik, is to write a context processor and add it to TEMPLATE_CONTEXT_PROCESSORS in the settings.py.
My question is, is this the right way to do it, considering that apps are supposed to be "independent" from the actual project using them?
In other words, when deploying that app to a new project, is there any way to avoid the project having to explicitly mess around with its settings? | How to add a context processor from a Django app | -0.066568 | 0 | 0 | 933 |
2,797,878 | 2010-05-09T14:12:00.000 | 1 | 0 | 0 | 0 | python,django,django-apps | 2,797,969 | 3 | true | 1 | 0 | Your assumption that apps can just be added in a project without touching the project's settings is not correct.
If you add an application to a project, you have to edit the settings, since you must add it in the INSTALLED_APPS tuple.
So why not edit the context processor list? | 2 | 1 | 0 | Say I'm writing a Django app, and all the templates in the app require a certain variable.
The "classic" way to deal with this, afaik, is to write a context processor and add it to TEMPLATE_CONTEXT_PROCESSORS in the settings.py.
My question is, is this the right way to do it, considering that apps are supposed to be "independent" from the actual project using them?
In other words, when deploying that app to a new project, is there any way to avoid the project having to explicitly mess around with its settings? | How to add a context processor from a Django app | 1.2 | 0 | 0 | 933 |
2,798,627 | 2010-05-09T18:16:00.000 | 0 | 1 | 1 | 1 | python,bash,file,line-breaks,line-endings | 2,798,651 | 7 | false | 0 | 0 | dos linebreaks are \r\n, unix only \n. So just search for \r\n. | 1 | 14 | 0 | I have a bunch of files. Some are Unix line endings, many are DOS. I'd like to test each file to see if if is dos formatted, before I switch the line endings.
How would I do this? Is there a flag I can test for? Something similar? | How can I detect DOS line breaks in a file? | 0 | 0 | 0 | 21,186 |
2,799,256 | 2010-05-09T21:30:00.000 | 1 | 0 | 0 | 1 | python,bash,shell,directory,terminal | 2,799,275 | 3 | false | 0 | 0 | Have you tried simply running the program in the current shell?
i.e
$. script.py
instead of
$script.py | 2 | 5 | 0 | I'm working on a simple Python script that can use subprocess and/or os to execute some commands, which is working fine.
However, when the script exits I'd like to cd the actual Terminal (in this case OS X) so on exit, the new files are ready to use in the directory where the have been created. All the following (subprocess.Popen, os.system, os.chdir) can do what I want from within the script (i.e. they execute stuff in the target directory) but on exit leave the Terminal at the script's own directory, not the target directory.
I'd like to avoid writing a shell script to temporary file just to achieve this, if this is at all possible anyway? | cd Terminal at a given directory after running a Python script? | 0.066568 | 0 | 0 | 2,631 |
2,799,256 | 2010-05-09T21:30:00.000 | 10 | 0 | 0 | 1 | python,bash,shell,directory,terminal | 2,799,281 | 3 | true | 0 | 0 | Sadly, no. Processes are not allowed to change the environment of their parent process, and in this case your Python script is a child process of the shell. You could "fake" it by having your Python process set up a new shell - call subprocess to open a shell process and present it to the user, inheriting the modified environment from itself - but that has the downside of forcing the Python process to run continually.
This is really what shell scripts are for.. :-) Someone clearly needs to write a more traditional shell (e.g. closer to Bash than IPython) which can use python as its scripting language. | 2 | 5 | 0 | I'm working on a simple Python script that can use subprocess and/or os to execute some commands, which is working fine.
However, when the script exits I'd like to cd the actual Terminal (in this case OS X) so on exit, the new files are ready to use in the directory where the have been created. All the following (subprocess.Popen, os.system, os.chdir) can do what I want from within the script (i.e. they execute stuff in the target directory) but on exit leave the Terminal at the script's own directory, not the target directory.
I'd like to avoid writing a shell script to temporary file just to achieve this, if this is at all possible anyway? | cd Terminal at a given directory after running a Python script? | 1.2 | 0 | 0 | 2,631 |
2,799,776 | 2010-05-10T00:45:00.000 | 1 | 0 | 0 | 0 | python,qt,pyqt | 2,801,458 | 1 | true | 0 | 1 | If you use the QGraphicsItem::pos(), it gives you the position of the item in the parent coordinates. When using QGraphicsLayout, the parent is probably the cell containing the object thus the coordinate is equal to zero.
Since you want to connect widgets with path, you will need scene coordinate to define the control points: use QGraphicsItem::scenePos() to obtain the position of your QGraphicsWidget in the scene. | 1 | 3 | 0 | I have a fairly simple PyQt application in which I'm placing instances of a QGraphicsWidget in a QGraphicsGridLayout and want to connect the widgets with lines drawn with a QGraphicsPath. Unfortunately, no matter what I try, I always get (0, 0) back as the position for both the start and end widgets.
I'm constructing the graph with a recursive function that adds widgets to the scene and layout. Once the recursive function is complete, the layout is added to a new widget, which is added to the scene to show everything. The edges are added to the scene as widgets are created.
How do I get a non-zero position of any of the widgets in the grid layout?
Update: I forgot to mention that I've tried both pos() and scenePos() on the widgets in the grid layout. Both always return (0, 0) as the position for every widget in the grid. | PyQt: Get the position of QGraphicsWidgets in a QGraphicsGridLayout | 1.2 | 0 | 0 | 2,688 |
2,800,231 | 2010-05-10T04:00:00.000 | 2 | 1 | 1 | 0 | python,unit-testing,python-2to3 | 2,800,242 | 2 | true | 0 | 0 | Simply use the -3 option with python2.6+ to be informed of Python3 compliance. | 2 | 4 | 0 | I have used the 2to3 utility to convert code from the command line. What I would like to do is run it basically as a unittest. Even if it tests the file rather than parts(functions, methods...) as would be normal for a unittest.
It does not need to be a unittest and I don't what to automatically convert the files I just want to monitor the py3 compliance of files in a unittest like manor. I can't seem to find any documentation or examples for this.
An example and/or documentation would be great. | use/run python's 2to3 as or like a unittest | 1.2 | 0 | 0 | 349 |
2,800,231 | 2010-05-10T04:00:00.000 | 1 | 1 | 1 | 0 | python,unit-testing,python-2to3 | 2,800,372 | 2 | false | 0 | 0 | If you are trying to verify the code will work in Python 3.x, I would suggest a script that copies the source files to a new directory, runs 2to3 on them, then copies the unit tests to the directory and runs them.
This may seem slightly inelegant, but is consistent with the spirit of unit testing. You are making a series of assertions that you believe ought to be true about the external behavior of the code, regardless of implementation. If the converted code passes your unit tests, you can consider your code to support Python 3. | 2 | 4 | 0 | I have used the 2to3 utility to convert code from the command line. What I would like to do is run it basically as a unittest. Even if it tests the file rather than parts(functions, methods...) as would be normal for a unittest.
It does not need to be a unittest and I don't what to automatically convert the files I just want to monitor the py3 compliance of files in a unittest like manor. I can't seem to find any documentation or examples for this.
An example and/or documentation would be great. | use/run python's 2to3 as or like a unittest | 0.099668 | 0 | 0 | 349 |
2,800,798 | 2010-05-10T06:46:00.000 | -1 | 0 | 0 | 1 | python,windows,macos,filesystems | 2,800,869 | 3 | false | 0 | 0 | os.popen('/sbin/fdisk -l /dev/sda') on Linux | 1 | 6 | 0 | I'm looking for a way in python to find out which type of file system is being used for a given path. I'm wanting to do this in a cross platform way. On linux I could just grab the output of df -T but that won't work on OSX or windows. | How to find the file system type in python | -0.066568 | 0 | 0 | 2,040 |
2,802,782 | 2010-05-10T13:06:00.000 | 1 | 0 | 0 | 0 | python,django,uninstallation,macports | 7,845,384 | 2 | false | 1 | 0 | django with Macport should work. py26-django or py27-django. It is the python version you are using that causes the problem.
Check to see if you are using the python comes with Mac or python installed via macport. Try python, python2.6, python2.7 from the terminal.
On my Mac (OSX 10.6.8) the default python version is 2.6.1. The macport version is 2.6.7.
You can replace the /usr/bin/python with the macport version by using 'ln -s' | 1 | 1 | 0 | I installed Django via Macports.
I wasted a lot of time on making it work.
It still does not work.
I would like to COMPLETELY uninstall Django (Macports) and install with the easy install (DJANGO).
I would like to keep Macports and not uninstall it, because I read it SHOULD be useful.
How can I achieve this?
Thank you for your attention. | Django Python Macports | 0.099668 | 0 | 0 | 3,721 |
2,804,964 | 2010-05-10T17:39:00.000 | 2 | 0 | 0 | 1 | python,unix,fork,subprocess,signals | 2,804,999 | 2 | false | 0 | 0 | I have come up with the idea of using a pipe file descriptor that the parent could write and then read/flush in combination with select, but this doesn't really qualify as a very elegant design.
In more detail: The parent would create a pipe, the subprocesses would inherit it, the parent process would write to the pipe, thereby waking up any subprocess select():ing on the file descriptor, but the parent would then immediately read from the read end of the pipe and empty it - the only effect being that those child processes that were select():ing on the pipe have woken up.
As I said, this feels odd and ugly, but I haven't found anything really better yet.
Edit:
It turns out that this doesn't work - some child processes are woken up and some aren't. I've resorted to using a Condition from the multiprocessing module. | 1 | 1 | 0 | I'm trying to find a good and simple method to signal child processes
(created through SocketServer with ForkingMixIn) from the parent
process.
While Unix signals could be used, I want to avoid them since only
children who are interested should receive the signal, and it would be
overkill and complicated to require some kind of registration
mechanism to identify to the parent process who is interested.
(Please don't suggest threads, as this particular program won't work
with threads, and thus has to use forks.) | How to "signal" interested child processes (without signals)? | 0.197375 | 0 | 0 | 651 |
2,806,397 | 2010-05-10T20:54:00.000 | 1 | 0 | 0 | 0 | python,multithreading,xml-rpc | 4,199,610 | 2 | false | 0 | 0 | You are doing what I usually call (originally in Spanish xD) "happy road programming". You should implement your programs to handle undesired cases, not only the ones you want to happen.
The threads here are only showing an underlying mistake: your server can't handle a timeout, and the implementation is rigid in a way that adding a timeout causes the server to crash due to an unhandled exception.
Implement it more robustly: it must be able to withstand an exception, servers can't die because of a misbehaving client. If you don't fix this kind of problem now, you may have similar issues later on. | 2 | 0 | 0 | I'm using threads and xmlrpclib in python at the same time. Periodically, I create a bunch of thread to complete a service on a remote server via xmlrpclib. The problem is that, there are times that the remote server doesn't answer. This causes the thread to wait forever for a response which it never gets. Over time, number of threads in this state increases and will reach the maximum number of allowed threads on the system (I'm using fedora).
I tried to use socket.setdefaulttimeout(10); but the exception that is created by that will cause the server to defunct. I used it at server side but it seems that it doesn't work :/
Any idea how can I handle this issue? | too many threads due to synch communication | 0.099668 | 0 | 1 | 110 |
2,806,397 | 2010-05-10T20:54:00.000 | 0 | 0 | 0 | 0 | python,multithreading,xml-rpc | 2,806,488 | 2 | false | 0 | 0 | It seems like your real problem is that the server hangs on certain requests, and dies if the client closes the socket - the threads are just a side effect of the implementation. If I'm understanding what you're saying correctly, then the only way to fix this would be to fix the server to respond to all requests, or to be more robust with network failure, or (preferably) both. | 2 | 0 | 0 | I'm using threads and xmlrpclib in python at the same time. Periodically, I create a bunch of thread to complete a service on a remote server via xmlrpclib. The problem is that, there are times that the remote server doesn't answer. This causes the thread to wait forever for a response which it never gets. Over time, number of threads in this state increases and will reach the maximum number of allowed threads on the system (I'm using fedora).
I tried to use socket.setdefaulttimeout(10); but the exception that is created by that will cause the server to defunct. I used it at server side but it seems that it doesn't work :/
Any idea how can I handle this issue? | too many threads due to synch communication | 0 | 0 | 1 | 110 |
2,806,806 | 2010-05-10T22:10:00.000 | 14 | 0 | 0 | 0 | python,memory,data-structures,graph | 2,806,868 | 8 | false | 0 | 0 | If that is 100-600 edges/node, then you are talking about 3.6 billion edges.
Why does this have to be all in memory?
Can you show us the structures you are currently using?
How much memory are we allowed (what is the memory limit you are hitting?)
If the only reason you need this in memory is because you need to be able to read and write it fast, then use a database. Databases read and write extremely fast, often they can read without going to disk at all. | 3 | 9 | 1 | I'm developing an application in which I need a structure to represent a huge graph (between 1000000 and 6000000 nodes and 100 or 600 edges per node) in memory. The edges representation will contain some attributes of the relation.
I have tried a memory map representation, arrays, dictionaries and strings to represent that structure in memory, but these always crash because of the memory limit.
I would like to get an advice of how I can represent this, or something similar.
By the way, I'm using python. | Huge Graph Structure | 1 | 0 | 0 | 6,997 |
2,806,806 | 2010-05-10T22:10:00.000 | 4 | 0 | 0 | 0 | python,memory,data-structures,graph | 2,806,891 | 8 | false | 0 | 0 | I doubt you'll be able to use a memory structure unless you have a LOT of memory at your disposal:
Assume you are talking about 600 directed edges from each node, with a node being 4-bytes (integer key) and a directed edge being JUST the destination node keys (4 bytes each).
Then the raw data about each node is 4 + 600 * 4 = 2404 bytes x 6,000,000 = over 14.4GB
That's without any other overheads or any additional data in the nodes (or edges). | 3 | 9 | 1 | I'm developing an application in which I need a structure to represent a huge graph (between 1000000 and 6000000 nodes and 100 or 600 edges per node) in memory. The edges representation will contain some attributes of the relation.
I have tried a memory map representation, arrays, dictionaries and strings to represent that structure in memory, but these always crash because of the memory limit.
I would like to get an advice of how I can represent this, or something similar.
By the way, I'm using python. | Huge Graph Structure | 0.099668 | 0 | 0 | 6,997 |
2,806,806 | 2010-05-10T22:10:00.000 | 0 | 0 | 0 | 0 | python,memory,data-structures,graph | 2,806,909 | 8 | false | 0 | 0 | Sounds like you need a database and an iterator over the results. Then you wouldn't have to keep it all in memory at the same time but you could always have access to it. | 3 | 9 | 1 | I'm developing an application in which I need a structure to represent a huge graph (between 1000000 and 6000000 nodes and 100 or 600 edges per node) in memory. The edges representation will contain some attributes of the relation.
I have tried a memory map representation, arrays, dictionaries and strings to represent that structure in memory, but these always crash because of the memory limit.
I would like to get an advice of how I can represent this, or something similar.
By the way, I'm using python. | Huge Graph Structure | 0 | 0 | 0 | 6,997 |
2,808,092 | 2010-05-11T04:33:00.000 | 0 | 0 | 0 | 0 | python,security,encryption,cryptography,udp | 2,808,130 | 6 | false | 0 | 0 | If you absolutely need to verify that a particular user is a particular user then you need to use some form of encryption where the user signs their messages. This can be done pretty quickly because the user only needs to generate a hash of their message and then sign (encrypt) the hash.
For your game application you probably don't need to worry about this. Most ISPs wont allow their users to spoof IP addresses thus you need to only worry about users behind NAT in which you may have multiple users running from the same IP address. In this case, and the general one, you can fairly safely identify unique users based on a tuple containing ip address and UDP port. | 3 | 8 | 0 | I have been creating an application using UDP for transmitting and receiving information. The problem I am running into is security. Right now I am using the IP/socketid in determining what data belongs to whom.
However, I have been reading about how people could simply spoof their IP, then just send data as a specific IP. So this seems to be the wrong way to do it (insecure). So how else am I suppose to identify what data belongs to what users? For instance you have 10 users connected, all have specific data. The server would need to match the user data to this data we received.
The only way I can see to do this is to use some sort of client/server key system and encrypt the data. I am curious as to how other applications (or games, since that's what this application is) make sure their data is genuine. Also there is the fact that encryption takes much longer to process than unencrypted. Although I am not sure by how much it will affect performance.
Any information would be appreciated. Thanks. | UDP security and identifying incoming data | 0 | 0 | 1 | 4,369 |
2,808,092 | 2010-05-11T04:33:00.000 | 0 | 0 | 0 | 0 | python,security,encryption,cryptography,udp | 7,210,998 | 6 | false | 0 | 0 | I would look into the Garage Games networking library. It is written in C++ and uses UDP. It is designed for low latency and is considered one of the best for games.
If I remember correctly they would actually calculate the likely position of the player both on the client side and the server side. It would do this for many aspects to ensure integrity of the data. It also would do a crc check on the client software and compare against the server software to make sure they matched.
I am not sure you can license it separately anymore so you may have to license the game engine (100 bucks). It would at least give you some insight on a proven approach to UDP for games. Another possibility is looking into the PyGame networking code. It may have already addressed the issues you are facing. | 3 | 8 | 0 | I have been creating an application using UDP for transmitting and receiving information. The problem I am running into is security. Right now I am using the IP/socketid in determining what data belongs to whom.
However, I have been reading about how people could simply spoof their IP, then just send data as a specific IP. So this seems to be the wrong way to do it (insecure). So how else am I suppose to identify what data belongs to what users? For instance you have 10 users connected, all have specific data. The server would need to match the user data to this data we received.
The only way I can see to do this is to use some sort of client/server key system and encrypt the data. I am curious as to how other applications (or games, since that's what this application is) make sure their data is genuine. Also there is the fact that encryption takes much longer to process than unencrypted. Although I am not sure by how much it will affect performance.
Any information would be appreciated. Thanks. | UDP security and identifying incoming data | 0 | 0 | 1 | 4,369 |
2,808,092 | 2010-05-11T04:33:00.000 | 0 | 0 | 0 | 0 | python,security,encryption,cryptography,udp | 2,815,170 | 6 | false | 0 | 0 | I'm breaking this down into four levels of security.
Extremely Insecure - Anyone on the network can spoof a valid request/response with generally available prior knowledge. (ie syslog)
Very Insecure - Anyone on the network can spoof a valid request/response only if they have at least read access to the wire. (Passive MITM) (ie http accessable forum with browser cookies)
Somewhat Insecure - Anyone in the network can spoof a valid request/response if they can read AND make changes to the wire (Active MITM) (ie https site with self-signed cert)
Secure - Requests/Responses cannot be spoofed even with full access to the
wire. (ie https accessable ecommerce site)
For Internet games the very insecure solution might actually be acceptable (It would be my choice) It requires no crypto. Just a field in your apps UDP packet format with some kind of random practically unguessable session identifier ferried around for the duration of the game.
Somewhat insecure requires a little bit of crypto but none of the trust/PKI/PSK needed to prevent Active-MITM of the secure solution. With somewhat insecure if the data payloads were not sensitive you could use an integrity only cipher with (TCP) TLS/ (UDP) DTLS to reduce processing overhead and latency at the client and server.
For games UDP is a huge benefit because if there is packet loss you don't want the IP stack to waste time retransmitting stale state - you want to send new state. With UDP there are a number of clever schemes such as non-acknowledged frames (world details which don't matter so much if their lost) and statistical methods of duplicating important state data to counter predictable levels of observed packet loss.
At the end of the day I would recommend go very insecure or somewhat insecure /w DTLS integrity only. | 3 | 8 | 0 | I have been creating an application using UDP for transmitting and receiving information. The problem I am running into is security. Right now I am using the IP/socketid in determining what data belongs to whom.
However, I have been reading about how people could simply spoof their IP, then just send data as a specific IP. So this seems to be the wrong way to do it (insecure). So how else am I suppose to identify what data belongs to what users? For instance you have 10 users connected, all have specific data. The server would need to match the user data to this data we received.
The only way I can see to do this is to use some sort of client/server key system and encrypt the data. I am curious as to how other applications (or games, since that's what this application is) make sure their data is genuine. Also there is the fact that encryption takes much longer to process than unencrypted. Although I am not sure by how much it will affect performance.
Any information would be appreciated. Thanks. | UDP security and identifying incoming data | 0 | 0 | 1 | 4,369 |
2,808,723 | 2010-05-11T07:15:00.000 | 14 | 0 | 0 | 0 | python,django,authentication | 2,809,873 | 6 | true | 1 | 0 | Your middleware suggestion got me thinking, and I now think the best idea is to overwrite the standard AuthenticationMiddleware. That class assigns a LazyUser object to the request, which is resolved to the correct user, when accessed, by calling contrib.auth.get_user. This is probably the right place to override things, so that it calls your customised get_user function which returns your subclassed AnonymousUser. | 2 | 14 | 0 | I want to make my User objects all have the same base behaviour and to do so I need to add a couple of methods / properties to Anonymous User.
I've already subclassed User to make richer user objects but I was wondering if anyone has done the same for Anonymous User? And if there are any preferred ways of doing it! | Whats the best way to extend Anonymous User in Django? | 1.2 | 0 | 0 | 5,125 |
2,808,723 | 2010-05-11T07:15:00.000 | 2 | 0 | 0 | 0 | python,django,authentication | 2,809,562 | 6 | false | 1 | 0 | I'm starting to think a middleware is probably the easiest solution that checks the request.user class and if is AnonymousUser then replaces it with a subclassed AnonymousUser that has the extra properties.
That sound reasonable? | 2 | 14 | 0 | I want to make my User objects all have the same base behaviour and to do so I need to add a couple of methods / properties to Anonymous User.
I've already subclassed User to make richer user objects but I was wondering if anyone has done the same for Anonymous User? And if there are any preferred ways of doing it! | Whats the best way to extend Anonymous User in Django? | 0.066568 | 0 | 0 | 5,125 |
2,808,956 | 2010-05-11T08:05:00.000 | 1 | 1 | 0 | 0 | python,installation,packaging,setuptools | 2,809,025 | 2 | false | 0 | 0 | It's better use apt-get to install lxml (or the python packages that has c extensions) and then pull pure python package from pypi. Also I generally try to avoid using easy_install for top level install, I rather create a virtual env using virtualenv and then use easy_install created by virtualenv to keep my setups clean.
This strategy is working successfully for me for couple of production environments. | 1 | 2 | 0 | I've got a Python module which is distributed on PyPI, and therefore installable using easy_install. It depends on lxml, which in turn depends on libxslt1-dev. I'm unable to install libxslt1-dev with easy_install, so it doesn't work to put it in install_requires. Is there any way I can get setuptools to install it instead of resorting to apt-get? | Installing Python egg dependencies without apt-get | 0.099668 | 0 | 0 | 1,090 |
2,809,578 | 2010-05-11T09:20:00.000 | 0 | 0 | 0 | 1 | python,disassembly | 2,814,647 | 5 | false | 1 | 0 | This is Brian, the question asker.
I have completed what I needed to do by just trial and error and hex editing, hex edit...then convert the source...see what I changed..until I finally narrowed down what I was looking for. The constants (Admin IDs) were in the hex file as converted hex (obviously) but backwards.
I still have no idea how or where I'd find the !=
I heard IDA Pro newest version supports python, but I havent learned how to get python to work on it. | 3 | 3 | 0 | I have 2 .pyo python files that I can convert to .py source files, but they don't compile perfectly as hinted by decompyle's verify.
Therefore looking at the source code, I can tell that config.pyo simply had variables in in an array:
ADMIN_USERIDS = [116901,
141,
349244,
39,
1159488]
I would like to take the original .pyo and disassembly or whatever I need to do inorder to change one of these IDs.
Or....
in model.pyo the source indicates a
if (productsDeveloperId != self.getUserId()):
All I would want to do is hex edit the != to be a == .....Simple with a windows exe program but I can't find a good python disassembler anywhere.
Any suggestions are welcomed...I am new to reading bytecode and new to python as well. | Reverse Engineer a .pyo python file | 0 | 0 | 0 | 7,406 |
2,809,578 | 2010-05-11T09:20:00.000 | 0 | 0 | 0 | 1 | python,disassembly | 2,809,684 | 5 | false | 1 | 0 | Convert the .pyo files to .py and then edit the .py and then run python on the .py files. Python will regenerate the .pyo files Don't edit the pyo
I don't know the python bytecode but I would doubt that the strings == or 1= would appear in the .pyo file
Although a much better way is get the original .py files and use them. If they give the wrong program as implied by wanting to change != to == then you could ask the supplier to fix the bug. | 3 | 3 | 0 | I have 2 .pyo python files that I can convert to .py source files, but they don't compile perfectly as hinted by decompyle's verify.
Therefore looking at the source code, I can tell that config.pyo simply had variables in in an array:
ADMIN_USERIDS = [116901,
141,
349244,
39,
1159488]
I would like to take the original .pyo and disassembly or whatever I need to do inorder to change one of these IDs.
Or....
in model.pyo the source indicates a
if (productsDeveloperId != self.getUserId()):
All I would want to do is hex edit the != to be a == .....Simple with a windows exe program but I can't find a good python disassembler anywhere.
Any suggestions are welcomed...I am new to reading bytecode and new to python as well. | Reverse Engineer a .pyo python file | 0 | 0 | 0 | 7,406 |
2,809,578 | 2010-05-11T09:20:00.000 | 0 | 0 | 0 | 1 | python,disassembly | 3,895,279 | 5 | false | 1 | 0 | IDA up to 6.0 doesn't have a .pyc decompilation module. | 3 | 3 | 0 | I have 2 .pyo python files that I can convert to .py source files, but they don't compile perfectly as hinted by decompyle's verify.
Therefore looking at the source code, I can tell that config.pyo simply had variables in in an array:
ADMIN_USERIDS = [116901,
141,
349244,
39,
1159488]
I would like to take the original .pyo and disassembly or whatever I need to do inorder to change one of these IDs.
Or....
in model.pyo the source indicates a
if (productsDeveloperId != self.getUserId()):
All I would want to do is hex edit the != to be a == .....Simple with a windows exe program but I can't find a good python disassembler anywhere.
Any suggestions are welcomed...I am new to reading bytecode and new to python as well. | Reverse Engineer a .pyo python file | 0 | 0 | 0 | 7,406 |
2,810,235 | 2010-05-11T11:28:00.000 | 1 | 0 | 0 | 0 | python,sqlite,pysqlite | 2,810,300 | 2 | true | 0 | 0 | when you create a prepared statement, the "template" SQL code is sent to the DBMS already, which compiles it into an expression tree. When you pass the values, the corresponding library (python sqlite3 module in your case) doesn't merge the values into the statement. The DBMS does.
If you still want to produce a normal SQL string, you can use string replace functions to replace the placeholders by the values (after escaping them).
What do you need this for? | 2 | 0 | 0 | If so, how can I do this? | Can I get the raw SQL generated by a prepared statement in Python’s sqlite3 module? | 1.2 | 1 | 0 | 848 |
2,810,235 | 2010-05-11T11:28:00.000 | 2 | 0 | 0 | 0 | python,sqlite,pysqlite | 2,810,250 | 2 | false | 0 | 0 | When executing a prepared statement, no new SQL is generated.
The idea of prepared statements is that the SQL query and its data are transmitted separately (that's why you don't have to escape any arguments) - the query is most likely only stored in an optimized form after preparing it. | 2 | 0 | 0 | If so, how can I do this? | Can I get the raw SQL generated by a prepared statement in Python’s sqlite3 module? | 0.197375 | 1 | 0 | 848 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.