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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4,270,192 | 2010-11-24T18:20:00.000 | 14 | 0 | 0 | 0 | python,django,python-3.x | 4,270,238 | 3 | true | 1 | 0 | No. Don't wait.
Why? Pretty much all django libraries are written for Python 2.x, and if you ever plan on using any of them with Python 3 with the next major release of Django then you'll be waiting not 1 but 3-4 years when everyone starts converting their code.
In this time, you could have already mastered django and could have worked and launched many sites, could've got a Django gig, etc.
Start immediately and don't postpone! | 3 | 8 | 0 | I have a website idea that I'm very excited about, and I love Python. So, I'm interested in using Django. However, I started learning Python in version 3.1, and Django currently only supports various 2.x versions. I've searched for information about when Django will start supporting Python 3.x, and gotten mostly articles from a year or two ago that say it will take a year or two. Meanwhile, the Django FAQ says that there are no immediate plans.
I'm reluctant to build in an old version of Python and then either be stuck with it or go through a huge ordeal trying to migrate later. My original solution to this was to start learning PHP instead and then choose a framework, but as it turns out I don't really like PHP. Django it is, then.
If I decide to wait for a 3.x-compatible version, I can teach myself more front-end web development (and more Python) in the meantime. I've only been at this for a few months so I have a lot to learn. But I don't want to wait forever, and I realize that even after a 3.x-compatible version comes out it will take a while for third-party APIs to catch up. What do you all recommend? | Should I wait for Django to start supporting Python 3? | 1.2 | 0 | 0 | 884 |
4,270,612 | 2010-11-24T19:15:00.000 | 2 | 0 | 0 | 0 | python,django,scrapy | 4,274,071 | 2 | false | 1 | 0 | for #1: Don't use rules attribute to extract links and follow, write your rule in parse function and yield or return Requests object.
for #2: Try scrapyd | 1 | 6 | 0 | I just got scrapy setup and running and it works great, but I have two (noob) questions. I should say first that I am totally new to scrapy and spidering sites.
Can you limit the number of links crawled? I have a site that doesn't use pagination and just lists a lot of links (which I crawl) on their home page. I feel bad crawling all of those links when I really just need to crawl the first 10 or so.
How do you run multiple spiders at once? Right now I am using the command scrapy crawl example.com, but I also have spiders for example2.com and example3.com. I would like to run all of my spiders using one command. Is this possible? | Scrapy Django Limit links crawled | 0.197375 | 0 | 0 | 1,211 |
4,270,893 | 2010-11-24T19:48:00.000 | 2 | 0 | 0 | 0 | python,django,markdown | 4,832,196 | 2 | false | 1 | 0 | I fixed this error by removing the .py extension from markdown.py in whatever/bin. This apparently prevented it from importing itself instead of the markdown module in site-packages. | 1 | 3 | 0 | I've got a weird error where I can import markdown in Python, and I can import markdown in python inside the Django runserver, but I get the following when trying to import markdown inside of gunicorn's app server.
* ImportError: cannot import name COMMAND_LINE_LOGGING_LEVEL
This is even more confusing because I found the only place where COMMAND_LINE_LOGGING_LEVEL is referenced in markdown (or any of the code I'm using) -- one line, defining it, in the markdown init.py, and I commented it out. I still get this error.
Any ideas? | Cannot import markdown because of COMMAND_LINE_LOGGING_LEVEL | 0.197375 | 0 | 0 | 1,564 |
4,271,089 | 2010-11-24T20:12:00.000 | 0 | 0 | 0 | 0 | python,django,django-admin | 4,271,834 | 3 | false | 1 | 0 | the django admin is more of a one size fits all kind of ui which may not be intuitive for use in some cases ..
customizing its look is easy but extending it is some how hard. you are better off designing your own views in that case. | 2 | 0 | 0 | Has anyone implemented their own AdminSite? How easy/hard was the basic implementation?
I'm in the midst of building a "cms" that's going to be quite large and decently complex in some areas and I'm wondering if using something like AdminSite would save some time. I'd rather not have to make my own implementation for admin actions and inlines and the like (I know I can just use inline forms but that's not as simple as inlines = [Foo]).
When using a custom AdminSite, is further customization equivalent to customizing the standard Django admin? | Django AdminSite - Difficult or Easy Implementation? | 0 | 0 | 0 | 633 |
4,271,089 | 2010-11-24T20:12:00.000 | 0 | 0 | 0 | 0 | python,django,django-admin | 4,271,476 | 3 | false | 1 | 0 | Both
If you are OK with it not doing exactly what you want its pretty much done for you automatically. If you need fine grain control over certain things it can be hard to customize without knowing the internals of the admin code. | 2 | 0 | 0 | Has anyone implemented their own AdminSite? How easy/hard was the basic implementation?
I'm in the midst of building a "cms" that's going to be quite large and decently complex in some areas and I'm wondering if using something like AdminSite would save some time. I'd rather not have to make my own implementation for admin actions and inlines and the like (I know I can just use inline forms but that's not as simple as inlines = [Foo]).
When using a custom AdminSite, is further customization equivalent to customizing the standard Django admin? | Django AdminSite - Difficult or Easy Implementation? | 0 | 0 | 0 | 633 |
4,271,740 | 2010-11-24T21:33:00.000 | 14 | 0 | 0 | 0 | python,hostname | 4,271,771 | 12 | false | 0 | 0 | socket.gethostname() could do | 1 | 833 | 0 | I'm writing a chat program for a local network. I would like be able to identify computers and get the user-set computer name with Python. | How can I use Python to get the system hostname? | 1 | 0 | 0 | 684,126 |
4,272,091 | 2010-11-24T22:23:00.000 | 0 | 0 | 1 | 0 | python,regex | 4,272,124 | 3 | false | 0 | 0 | (?<=#TR=[)[^]]*(?=]) | 1 | 0 | 0 | How to find everything which goes after symols #TR= and it is inside [ ] using re module. For example #TR=[ dfgg dfgddfg dgfgf dgdgdg dfgfg ] | Python. Regular expression | 0 | 0 | 0 | 218 |
4,273,169 | 2010-11-25T02:03:00.000 | 2 | 0 | 0 | 0 | python,algorithm,filtering,prediction,collaborative | 5,586,430 | 2 | false | 0 | 0 | I think it might work, but I would apply log to the number of tries (you can't do log(0) so retries won't work) first. If someone found a level easy they would try it once or twice, whereas people who found it hard would generally have to do it over and over again. The difference between did it in 1 go vs 2 goes is much greater than 20 goes vs 21 goes. This would remove the need to place an arbitrary limit on the number of goes value. | 1 | 8 | 1 | I am planning to use SlopeOne algorithm to predict if a gamer can complete a given level in a Game or not?
Here is the scenario:
Lots of Gamers play and try to complete 100 levels in the game.
Each gamer can play a level as many times as they want until they cross the level.
The system keeps track of the level and the number of ReTries for each level.
Each Game Level falls into one of the 3 categories (Easy, Medium, Hard)
Approximate distribution of the levels is 33% across each category meaning 33% of the levels are Easy, 33% of the levels are Hard etc.
Using this information:
When a new gamer starts playing the game, after a few levels, I want to be able to predict
which level can the Gamer Cross easily and which levels can he/she not cross easily.
with this predictive ability I would like to present the game levels that the user would be able to cross with 50% probability.
Can I use SlopeOne algorithm for this?
Reasoning is I see a lot of similarities between what I want to with say a movie rating system.
n users, m items and N ratings to predict user rating for a given item.
Similarly, in my case, I have
n users, m levels and N Retries ...
The only difference being in a movie rating system the rating is fixed on a 1-5 scale and in my case the retries can range from 1-x (x could be as high as 30)
while theoretically someone could retry more 30 times, for now I could start with fixing the upper limit at 30 and adjust after I have more data.
Thanks. | Using SlopeOne algorithm to predict if a gamer can complete a level in a Game? | 0.197375 | 0 | 0 | 431 |
4,273,466 | 2010-11-25T03:18:00.000 | 4 | 0 | 0 | 0 | python,hash | 4,273,543 | 5 | false | 0 | 0 | Why not just XOR with a nice long number?
Easy. Fast. Reversible.
Or, if this doesn't need to be terribly secure, you could convert from base 10 to some smaller base (like base 8 or base 4, depending on how long you want the numbers to be). | 2 | 50 | 1 | I need a reversible hash function (obviously the input will be much smaller in size than the output) that maps the input to the output in a random-looking way. Basically, I want a way to transform a number like "123" to a larger number like "9874362483910978", but not in a way that will preserve comparisons, so it must not be always true that, if x1 > x2, f(x1) > f(x2) (but neither must it be always false).
The use case for this is that I need to find a way to transform small numbers into larger, random-looking ones. They don't actually need to be random (in fact, they need to be deterministic, so the same input always maps to the same output), but they do need to look random (at least when base64encoded into strings, so shifting by Z bits won't work as similar numbers will have similar MSBs).
Also, easy (fast) calculation and reversal is a plus, but not required.
I don't know if I'm being clear, or if such an algorithm exists, but I'd appreciate any and all help! | Reversible hash function? | 0.158649 | 0 | 0 | 47,252 |
4,273,466 | 2010-11-25T03:18:00.000 | 19 | 0 | 0 | 0 | python,hash | 4,274,259 | 5 | false | 0 | 0 | What you are asking for is encryption. A block cipher in its basic mode of operation, ECB, reversibly maps a input block onto an output block of the same size. The input and output blocks can be interpreted as numbers.
For example, AES is a 128 bit block cipher, so it maps an input 128 bit number onto an output 128 bit number. If 128 bits is good enough for your purposes, then you can simply pad your input number out to 128 bits, transform that single block with AES, then format the output as a 128 bit number.
If 128 bits is too large, you could use a 64 bit block cipher, like 3DES, IDEA or Blowfish.
ECB mode is considered weak, but its weakness is the constraint that you have postulated as a requirement (namely, that the mapping be "deterministic"). This is a weakness, because once an attacker has observed that 123 maps to 9874362483910978, from then on whenever she sees the latter number, she knows the plaintext was 123. An attacker can perform frequency analysis and/or build up a dictionary of known plaintext/ciphertext pairs. | 2 | 50 | 1 | I need a reversible hash function (obviously the input will be much smaller in size than the output) that maps the input to the output in a random-looking way. Basically, I want a way to transform a number like "123" to a larger number like "9874362483910978", but not in a way that will preserve comparisons, so it must not be always true that, if x1 > x2, f(x1) > f(x2) (but neither must it be always false).
The use case for this is that I need to find a way to transform small numbers into larger, random-looking ones. They don't actually need to be random (in fact, they need to be deterministic, so the same input always maps to the same output), but they do need to look random (at least when base64encoded into strings, so shifting by Z bits won't work as similar numbers will have similar MSBs).
Also, easy (fast) calculation and reversal is a plus, but not required.
I don't know if I'm being clear, or if such an algorithm exists, but I'd appreciate any and all help! | Reversible hash function? | 1 | 0 | 0 | 47,252 |
4,273,729 | 2010-11-25T04:29:00.000 | 5 | 0 | 1 | 0 | python,virtualenv | 4,273,823 | 2 | true | 0 | 0 | You can also (on UNIX) symlink specific packages from the Python site-packages into your virtualenv's site-packages. | 1 | 4 | 0 | When creating a virtual environment with no -site packages do I need to install mysql & the mysqldb adapter which is in my global site packages in order to use them in my virtual project environment? | Python Virtualenv | 1.2 | 1 | 0 | 920 |
4,273,939 | 2010-11-25T05:12:00.000 | 3 | 0 | 1 | 1 | python,windows,subprocess,runas | 4,274,871 | 3 | false | 0 | 0 | Another option is to popen not the desired process but runas ... command. Note that the Run As service should be enabled and running. | 1 | 7 | 0 | What is the best manner of launching a subprocess as a different user in Python on Windows? Preferably XP and up, but if it works only on Vista and 7, I can live with that too. | Python subprocess.Popen as different user on Windows | 0.197375 | 0 | 0 | 10,165 |
4,274,207 | 2010-11-25T06:09:00.000 | -1 | 0 | 1 | 0 | python | 4,274,234 | 4 | false | 0 | 0 | I don't know python but it should be possible to convert the string into an array , then iterate thru the array to create a dictionary by alternating name & value. | 1 | 0 | 0 | I'd like to take a string containing tuples that are not well separated and convert them into a dictionary.
s = "banana 4 apple 2 orange 4"
d = {'banana':'4', 'apple':'2', 'orange':'4'}
I'm running into a problem because the space is used to separate the values as well as the pairs. What's the right trick? | How can you convert a list of poorly formed data pairs into a dict? | -0.049958 | 0 | 0 | 634 |
4,276,342 | 2010-11-25T11:10:00.000 | 1 | 0 | 0 | 0 | python,line,pygame | 4,276,397 | 3 | true | 0 | 1 | If you use screen.fill([0,0,0]) it will fill in the background (or whatever you have set to be your background).
This will erase any lines drawn on the image, essentially removing anything drawn on the background. | 1 | 0 | 0 | I'm using pygame to create a small scene. Right now, I'm working with lines.
I have an array of lines which are drawn to the screen and when a line is deleted from the array, I would like the line to disappear from the screen.
The problem I've found is that the line is drawn on the screen and remains static. I can't find a way to reset the screen (I'm using a JPEG as the background).
Is there a way to remove a drawn line from the screen?
Thanks | Python (pygame): How can I delete a line? | 1.2 | 0 | 0 | 4,502 |
4,276,850 | 2010-11-25T12:05:00.000 | 4 | 0 | 0 | 0 | python,pygame,transparent | 4,535,566 | 4 | true | 0 | 1 | After checking both PyGame and SDL documentations I came to conclusion that what I asked wasn't doable in PyGame using standard functions.
SDL docs state that per-pixel alpha and per-surface alpha cannot be combined with the former always taking the precedence. The only way to achieve the effect I want is by writing a code which updates per-pixel alpha values of the source surface before the blit. | 1 | 13 | 0 | Is it possible to display PyGame surfaces with controllable alpha? I would like to take a surface with its own per pixel alpha and display it with variable level of translucency without affecting the surface data and keep the transparency intact i.e. the objects on the surface would keep their shapes but their "contents" becoming more or less translucent.
In other words I want to combine per-pixel alpha from the source image with per-surface alpha calculated at the runtime. | PyGame: translucent sprites with per pixel alpha | 1.2 | 0 | 0 | 7,315 |
4,278,444 | 2010-11-25T15:08:00.000 | 1 | 1 | 0 | 0 | python,file-io,cython | 8,262,264 | 1 | false | 0 | 1 | Would it be too inefficient to call os.fdopen() on the file descriptor number returned by the underlying library, and then to dispatch normal Python method calls to the resulting file object in order to do your input and output? With most I/O, I would be surprised if you could see a difference with whether you called a C routine directly or let the Python method dispatch logic call it for you — but, of course, you might be in an unusual situation and I could be wrong! | 1 | 20 | 0 | I need to expose a file-like object from a C library that i'm wrapping with a Cython module. I want to reuse python's generic io code for stuff like buffering, readline(), etc.
The new IO module seems to be just what i need, but actually using it from Cython seems to be non-trivial, I've tried several aproaches:
My code in a cdef class that inherits from IO.RawIOBase - This fails because cdef classes can inherit only from other cython cdef classes, while IO is "raw" C.
My code in a cdef class, another (non-cdef) class that inherits both my cdef class and RawIOBase - Fails with "TypeError: multiple bases have instance lay-out conflict"
My code in a (non-cdef) class that inherits from RawIOBase - This works, but i loose the ability to store my c-level (that i need to talk to the underlying library) stuff inside the class, so i need a make a cdef wrapper around it and store that as a member... this looks like a mess.
My code in cdef class that doesn't inherit (Raw)IOBase rather reimplements it's functionality, Python code gets my object wrapped in BufferedReader/BufferedWriter - This one seems to work and less messy than the previous option.
My questions(s):
1) Am I missing something and reinventing the wheel here?
2) What is the exact stuff from IOBase that I need to implement to keep BufferedReader/Writer happy with my object in current and future versions of python? Is this documented anywhere?
3) How will that work in python 2.6 where IO is pure python? I guess that performance will suffer but it will work, right? | Exposing a file-like object from Cython | 0.197375 | 0 | 0 | 1,145 |
4,278,461 | 2010-11-25T15:10:00.000 | 1 | 0 | 0 | 0 | python,user-interface,tkinter,ffdshow | 4,278,800 | 1 | false | 0 | 1 | That is precisely the type of thing that python and Tkinter excel at. And yes, a relative newbie can easily do a task like that. | 1 | 1 | 0 | I was thinking that for a learning project for myself, I would try to make a GUI for ffdshow on linux, using tkinter. Wanted to make sure this project would be feasible first, before I get halfway through and run into something that cant be done in python.
Basic idea is to have a single GUI window with a bunch of drop down boxes that have the various presets (like format or bitrate), as well as a text box where a custom number can be entered if applicable. Then when all the options are selected, the user hits the Start button on the GUI and it shows a progress little bar with a percentage. All the options selected would just send the relevant selections as cli arguments for ffdshow, and begin the conversion progress (essentially turning all the user's input into a single perfect cli command).
Is all this doable with python and tkinter? and is it something that a relative newb with only very basic tkinter experience could pull off with books and other python resources?
Thanks | making a python gui for ffdshow | 0.197375 | 0 | 0 | 446 |
4,278,476 | 2010-11-25T15:11:00.000 | 0 | 0 | 0 | 0 | python,ruby-on-rails,ruby,django,deployment | 4,279,176 | 6 | false | 1 | 0 | At the moment Rails has better tools for deployment. Of course you can use Capistrano and other tools mentioned in this thread with Python/Django as well, it just mean you have to learn some bits of Ruby notation.
Fabric is great and feels more natural if you are Python person however has much less out-of-the-box functionality. | 2 | 1 | 0 | I'm looking for at either Rails or Django for some opensource development..
I recently tried to install Gitorious (awesome rails app) on a server..
Gave up after about 4 days of crying at 3AM,
Which is generally the easiest to deploy?
Thanks
Daniel | Rails vs Django Deployment | 0 | 0 | 0 | 1,629 |
4,278,476 | 2010-11-25T15:11:00.000 | 1 | 0 | 0 | 0 | python,ruby-on-rails,ruby,django,deployment | 4,278,840 | 6 | false | 1 | 0 | HELLO,
You can use passenger to deploy your rails application without pain :) Capistrano and webistrano are alternatives too | 2 | 1 | 0 | I'm looking for at either Rails or Django for some opensource development..
I recently tried to install Gitorious (awesome rails app) on a server..
Gave up after about 4 days of crying at 3AM,
Which is generally the easiest to deploy?
Thanks
Daniel | Rails vs Django Deployment | 0.033321 | 0 | 0 | 1,629 |
4,279,885 | 2010-11-25T18:20:00.000 | 0 | 0 | 0 | 0 | python,django,django-models,django-views,django-testing | 4,285,854 | 6 | false | 1 | 0 | I also had this problem before,
may be you could install ipython,which has a magic function called like this:
%save.
This will save what you input into a file .
and ipython is a very charming tool ,which can take the palce of standard python prompt perfectly.. It also have other wonderful things !
And in django , if you have install ipython, when you input python manage.py shell,
it will invoke ipython directly. | 1 | 0 | 0 | I am still in the development phase of a Django App. Before even writing my views.py, I test them out to see if my models are correctly defined. This I do it in the terminal by invoking
python manage.py shell
But oh so often I make some syntax error prompting me to abort the shell ctrl-D & retype everything. This process is taking forever. It would be better if I could write all this in some file just for my trials & if all's well copy it to views.py.
What's the process for this? Is it as simple as creating a trial.py in my app directory. Won't I have to import the Django env? What's the best way to do this? | Test out small snippets of Django code | 0 | 0 | 0 | 330 |
4,280,432 | 2010-11-25T19:50:00.000 | 1 | 0 | 0 | 1 | python,linux,multithreading,signals | 4,280,474 | 3 | false | 0 | 0 | About the only thing you can do is set a global variable from your signal handler, and have your threads check its value periodically. | 2 | 1 | 0 | hello to you all :)
i have a program that have a n number of threads(could be a lot) and they do a pretty extensive job. My problem is that sometimes some people turn off or reboot the server(the program runs all day in the company servers) i know that there is a way to make a handler for the linux signals i want to know what i should do to interact with all threads making them to use run a function and then stop working. There is a way to do that?
sorry the bad english :P | receiving a linux signal and interating with threads | 0.066568 | 0 | 0 | 474 |
4,280,432 | 2010-11-25T19:50:00.000 | 3 | 0 | 0 | 1 | python,linux,multithreading,signals | 4,280,803 | 3 | true | 0 | 0 | The best way of handling this is not requiring any shutdown actions at all.
For example, your signal handler for (e.g.) SIGTERM or SIGQUIT can just call _exit and quit the process with no clean-up.
Under Linux (with non-ancient threads) when one thread calls _exit (or exit if you really want) other threads get stopped too - whatever they were in the middle of doing.
This would be good as it implements a crash-only design.
Crash-only design for a server is based on the principle that the machine may crash at any point, so you need to be able to recover from such a failure anyway, so just make it the normal way of quitting. No extra code should be required as your server should be robust enough anyway. | 2 | 1 | 0 | hello to you all :)
i have a program that have a n number of threads(could be a lot) and they do a pretty extensive job. My problem is that sometimes some people turn off or reboot the server(the program runs all day in the company servers) i know that there is a way to make a handler for the linux signals i want to know what i should do to interact with all threads making them to use run a function and then stop working. There is a way to do that?
sorry the bad english :P | receiving a linux signal and interating with threads | 1.2 | 0 | 0 | 474 |
4,280,885 | 2010-11-25T21:13:00.000 | 0 | 1 | 0 | 0 | python,openssl,m2crypto | 5,480,356 | 1 | false | 0 | 0 | I don't have 10.4.11, but I do have 10.5.8 with Python 2.6.5 and OpenSSL 0.9.8n and everything works without a problem. Please try with latest M2Crypto. If that does not work, try getting and compiling OpenSSL yourself and configuring M2Crypto to use that. Maybe something is wrong with your current OpenSSL. | 1 | 0 | 0 | Importing M2Crypto version 0.20.2 on python 2.6.5 fails when M2Crypto was compiled against a recent openssl versions (0.9.8x or higher) on MAC OS X 10.4.11:
Even though the compilation works against these openssl version, M2Crypto fails to import, because a missing symbol: _PEM_read_bio_EC_PUBKEY
Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import M2Crypto
Traceback (most recent call last):
File "", line 1, in
File "M2Crypto/init.py", line 22, in
import _m2crypto
ImportError: dlopen(M2Crypto/_m2crypto.so, 2): Symbol not found: _PEM_read_bio_EC_PUBKEY
Referenced from: M2Crypto/__m2crypto.so
Expected in: dynamic lookup
If I compile M2Crypto against openssl version 0.9.7l or 0.9.7m it works just fine.
Any suggestion? | Symbol not found: _PEM_read_bio_EC_PUBKEY Importing M2Crypto-0.20.2 when compiled against openssl 0.9.8x or 1.0.0x | 0 | 0 | 0 | 257 |
4,281,190 | 2010-11-25T22:13:00.000 | 0 | 1 | 1 | 0 | python,pycharm | 4,281,235 | 3 | false | 0 | 0 | Not a pro on this but I think you have to use the module name preceding the method you want to call. For example to call a function named doStuff in the settings module call settings.doStuff().
To call the methods directly you need to use "from settings import *". But I think this method is frowned upon. | 1 | 0 | 0 | Is it possible to configure PyCharm in the following way:
Request auto-completion on any letter key press
Complete on space press, instead of enter
Request completion for modules not in path
I mean, configure it in VS-way.
Also, VS-like hotkeys will be amazing option | PyCharm imports and code completion | 0 | 0 | 0 | 1,813 |
4,283,639 | 2010-11-26T08:32:00.000 | 4 | 0 | 1 | 0 | python,file,equality | 4,283,664 | 6 | false | 0 | 0 | Ok, this might need two separate answers.
If you have many files to compare, go for the checksum and cache the checksum for each file. To be sure, compare matching files byte for byte afterwards.
If you have only two files, go directly for byte comparison because you have to read the file anyway to compute the checksum.
In both cases, use the file size as an early way of checking for inequality. | 2 | 5 | 0 | what's the most elegant way to check to files for equality in Python?
Checksum? Bytes comparing? Think files wont' be larger than 100-200 MB | check files for equality | 0.132549 | 0 | 0 | 10,060 |
4,283,639 | 2010-11-26T08:32:00.000 | -2 | 0 | 1 | 0 | python,file,equality | 4,283,665 | 6 | false | 0 | 0 | I would do checksum with MD5 (for example) instead of byte comaprasion plus the date check and depend on you needs name check. | 2 | 5 | 0 | what's the most elegant way to check to files for equality in Python?
Checksum? Bytes comparing? Think files wont' be larger than 100-200 MB | check files for equality | -0.066568 | 0 | 0 | 10,060 |
4,285,237 | 2010-11-26T12:20:00.000 | 10 | 0 | 1 | 0 | python,assert,cython | 4,285,513 | 2 | false | 0 | 0 | Cython skips the assertions if you define the C preprocessor macro PYREX_WITHOUT_ASSERTIONS. So pass -DPYREX_WITHOUT_ASSERTIONS to the C compiler when compiling the generated C file. How to to this depends on your build process. | 1 | 6 | 0 | so, here is my problem:
I code in python, but I need to improve performance in some part of my code that are too slow. A good(and easy) solution seems to be using cython; I tried it and got good results.
The issue is that I use assert statement in my python code. Before using cython, I could compile my python code with the -OO option, so that I can deliver a version not executing any assertion test, and still have the assert for debug. But the files that are compiled in cython seems to always execute the asserts. Is there some options that can be passed to cython compilation to remove(or not remove) the assertions? | How to remove python assertion when compiling in cython? | 1 | 0 | 0 | 2,337 |
4,285,388 | 2010-11-26T12:46:00.000 | 0 | 0 | 0 | 0 | python,django | 4,287,426 | 4 | false | 1 | 0 | 1) ModelAdmin, you can customize the Forms for CRUD operations with this.
2) Overload your Admin Templates
3) Admin Tools and Grappelli provide great options to extend and customize the Django Admin
sorry, i can't post links but google can help easily with 1) and 2) searchs. | 1 | 1 | 0 | How to customize the look and feel of django admin? | How to customize the look and feel of django admin | 0 | 0 | 0 | 1,478 |
4,287,941 | 2010-11-26T19:06:00.000 | 27 | 1 | 0 | 0 | python,rabbitmq,amqp | 4,288,304 | 8 | true | 0 | 0 | As far as I know, there isn't any way of doing this. That's nothing to do with Python, but because AMQP doesn't define any method of queue discovery.
In any case, in AMQP it's clients (consumers) that declare queues: publishers publish messages to an exchange with a routing key, and consumers determine which queues those routing keys go to. So it does not make sense to talk about queues in the absence of consumers. | 2 | 42 | 0 | I need to have a python client that can discover queues on a restarted RabbitMQ server exchange, and then start up a clients to resume consuming messages from each queue. How can I discover queues from some RabbitMQ compatible python api/library? | How can I list or discover queues on a RabbitMQ exchange using python? | 1.2 | 0 | 1 | 70,261 |
4,287,941 | 2010-11-26T19:06:00.000 | 2 | 1 | 0 | 0 | python,rabbitmq,amqp | 4,289,172 | 8 | false | 0 | 0 | Management features are due in a future version of AMQP. So for now you will have to wait till for a new version that will come with that functionality. | 2 | 42 | 0 | I need to have a python client that can discover queues on a restarted RabbitMQ server exchange, and then start up a clients to resume consuming messages from each queue. How can I discover queues from some RabbitMQ compatible python api/library? | How can I list or discover queues on a RabbitMQ exchange using python? | 0.049958 | 0 | 1 | 70,261 |
4,288,731 | 2010-11-26T21:47:00.000 | 0 | 0 | 1 | 0 | python,debugging | 4,288,853 | 5 | false | 0 | 0 | What you can do is use twisted.python and write the traceback to a file, it gives you an exact traceback including the exception | 1 | 6 | 0 | I'm looking for a way to debug a python exception "retrospectively". Essentially if my program raises an exception that isn't handled, I want it to save off the program state so I can go back later and debug the problem.
I've taken a look at the pdb docs, and it seems that you can do this, but only if you can interact with the program at the point of the exception. This won't work for me as the program will be run in the background (without a controlling terminal).
My first (doomed!) approach was to put a try/except block at the highest level of my program, and in the except block extract the traceback object from the current exception and write it to disk using pickle. I planned to then write a separate program that would unpickle the object and use pdb.post_mortem to debug the crashed program. But traceback objects aren't pickleable, but I wouldn't expect that to work anyway, as it wouldn't save off the entire program state. | How can I retrospectively debug a python exception | 0 | 0 | 0 | 995 |
4,289,113 | 2010-11-26T23:09:00.000 | 4 | 0 | 0 | 0 | python,django,django-admin,modeladmin | 15,231,605 | 2 | false | 1 | 0 | If you write a method and add it to ModelAdmin.readonly_fields, it will appear on the change view. | 1 | 3 | 0 | I'd like to add a derived field to a default ModelAdmin.fieldsets like I would by specifying a method and adding it to the ModelAdmin.list_display property, but there doesn't seem to be an easy way to do that (if there is ANY way to do that).
The default Django Admin list view seems to have a lot more options than the change form view does.
Let's say I have two fields for a location: latitude and longitude, and instead of displaying them on a change form I want to display a Google Maps Static Map image instead - I already have a method that will return the src url for the image - I just need a way to add that image to the model change form instead of showing those two fields. | Add Derived Field to Django Admin Change Form | 0.379949 | 0 | 0 | 2,379 |
4,290,359 | 2010-11-27T05:58:00.000 | 0 | 0 | 1 | 0 | python,database,dictionary,pickle | 4,290,376 | 3 | false | 0 | 0 | I would think that storing it as a dictionary in a python file and importing into every module that needs it would be the way to go. Can you construct it programmatically? Either way, the file will only be actually imported once per program execution so it shouldn't be a big deal unless you know that loading it once at the beginning is unacceptable for some reason.
shelve could be another way to go here. This would probably be the way to do it if you wanted to go with option (3) It's built on the anydbm module. This will probably be slower but will allow you to avoid having the whole thing in memory at once.
In my opinion, both 1) and 3) are right out. The overhead of making the database queries would, in all probability, slow access down dramatically. Option 2) will make it all a simple dict lookup. | 2 | 3 | 0 | I have what is a Python dictionary of ~1000 entries. A script is going to be called repeatedly that will want to parse a string and see if any keys in the string match. If they do, it will take some action based on the key and the value.
Which of these is faster?
1) Store the dictionary in a MySQL database, and then read the database each time the script is called?
2) Store the dictionary in a Python script and import it every time? (e.g. make a file that contains nothing but the dictionary initialization)
3) Store the dictionary in a text file, and import it every time? (either a flat text file or a pickle serialized data file, using cpickle)
Just looking for a best practice here. | What's the most efficient way to load a dictionary in Python? | 0 | 0 | 0 | 3,522 |
4,290,359 | 2010-11-27T05:58:00.000 | 1 | 0 | 1 | 0 | python,database,dictionary,pickle | 4,290,384 | 3 | true | 0 | 0 | You might create a .py Python file that just assigns the dictionary to a name. Save the file. Compile the file to a .pyc then load it as a module when needed by your main Python script.
You get the advantage of keeping a readable textual representation of your dict for maintenance/debug, the speed of loading a .pyc file and the simplicity of it all being standard Python. | 2 | 3 | 0 | I have what is a Python dictionary of ~1000 entries. A script is going to be called repeatedly that will want to parse a string and see if any keys in the string match. If they do, it will take some action based on the key and the value.
Which of these is faster?
1) Store the dictionary in a MySQL database, and then read the database each time the script is called?
2) Store the dictionary in a Python script and import it every time? (e.g. make a file that contains nothing but the dictionary initialization)
3) Store the dictionary in a text file, and import it every time? (either a flat text file or a pickle serialized data file, using cpickle)
Just looking for a best practice here. | What's the most efficient way to load a dictionary in Python? | 1.2 | 0 | 0 | 3,522 |
4,291,319 | 2010-11-27T11:08:00.000 | 0 | 1 | 0 | 0 | python-twitter | 4,291,535 | 1 | true | 0 | 0 | They might have a limit of requests in a certain amount of time or they had a failure on the system. You can ask for new credentials to see if the problem was the first one and try getting the tweets with them. | 1 | 0 | 0 | My code was working correctly till yesterday and I was able to fetch tweets, from GetSearch(), but now it is returning empty list, though I check my credentials are correct
Is something changed recently??
Thank you | python-twitter GetSearch giving empty list | 1.2 | 0 | 1 | 297 |
4,291,401 | 2010-11-27T11:30:00.000 | 2 | 1 | 0 | 0 | c#,python,c | 4,291,519 | 6 | false | 0 | 0 | You always need to know enough c to port headers to your language of choice when there are no ports for a library you want to use yet. Many libraries are written in c since then they can be used from almost all platforms/languages. | 5 | 1 | 0 | I have been working as a web dev with C#, VB and PHP (now learning python)..
I have been considering learning C (as a right of passage) because i hate feeling stupid =P
Apart from making me a better programmer in general..
Is there any particualr use to C for a Web Dev in 2010?
Thanks,
Daniel | Is there any merit to a web developer learning C? | 0.066568 | 0 | 0 | 241 |
4,291,401 | 2010-11-27T11:30:00.000 | 0 | 1 | 0 | 0 | c#,python,c | 4,291,408 | 6 | false | 0 | 0 | no :)
C is not targeted for web development | 5 | 1 | 0 | I have been working as a web dev with C#, VB and PHP (now learning python)..
I have been considering learning C (as a right of passage) because i hate feeling stupid =P
Apart from making me a better programmer in general..
Is there any particualr use to C for a Web Dev in 2010?
Thanks,
Daniel | Is there any merit to a web developer learning C? | 0 | 0 | 0 | 241 |
4,291,401 | 2010-11-27T11:30:00.000 | 2 | 1 | 0 | 0 | c#,python,c | 4,293,283 | 6 | false | 0 | 0 | Learning C won't necessarily make you a better programmer; there's a superstition that because C is moderately difficult to learn (true) and doesn't have an extensive toolkit (also true), you gain a deeper insight into programming in general (not necessarily true). C's just another language, no better or worse than any other. You'd get as much benefit learning Fortran. If you're really interested in how things work at the machine/OS level, you'd be better served learning an assembler; just remember that assemblers are specific to their platforms, and some of the concepts that apply to x86 don't apply to other platforms such as MIPS or PPC.
Learning C won't help you much in your day-to-day work in web development.
Having said that, it's always a good idea to pick up new languages if you can, especially languages that are as different as possible from what you're currently using, just because it helps you to learn the difference between a general programming concept vs. a particular language's implementation of that concept. I've seen plenty of people proficient in a language like C# flail helplessly when forced to work in C because all of their shiny tools are missing. | 5 | 1 | 0 | I have been working as a web dev with C#, VB and PHP (now learning python)..
I have been considering learning C (as a right of passage) because i hate feeling stupid =P
Apart from making me a better programmer in general..
Is there any particualr use to C for a Web Dev in 2010?
Thanks,
Daniel | Is there any merit to a web developer learning C? | 0.066568 | 0 | 0 | 241 |
4,291,401 | 2010-11-27T11:30:00.000 | 1 | 1 | 0 | 0 | c#,python,c | 4,292,028 | 6 | false | 0 | 0 | Given that you have experience of object orientated programming in C#, I would recommend learning C++ as opposed to C. It will indeed make you a more rounded programmer. While you could program web sites using C or C++, it's not commonly done for small scale web sites. Facebook created HipHop for PHP for instance to improve performance:
HipHop programmatically transforms your PHP source code into highly optimized C++ and then uses g++ to compile it.
Good luck with your learning, never stop :-) | 5 | 1 | 0 | I have been working as a web dev with C#, VB and PHP (now learning python)..
I have been considering learning C (as a right of passage) because i hate feeling stupid =P
Apart from making me a better programmer in general..
Is there any particualr use to C for a Web Dev in 2010?
Thanks,
Daniel | Is there any merit to a web developer learning C? | 0.033321 | 0 | 0 | 241 |
4,291,401 | 2010-11-27T11:30:00.000 | 4 | 1 | 0 | 0 | c#,python,c | 4,291,457 | 6 | false | 0 | 0 | Learning C (or, for the added fun, C++) as a device of increasing your understanding of programming is a good idea IMHO. But it doesn't have anything to offer you as regards web development. | 5 | 1 | 0 | I have been working as a web dev with C#, VB and PHP (now learning python)..
I have been considering learning C (as a right of passage) because i hate feeling stupid =P
Apart from making me a better programmer in general..
Is there any particualr use to C for a Web Dev in 2010?
Thanks,
Daniel | Is there any merit to a web developer learning C? | 0.132549 | 0 | 0 | 241 |
4,291,566 | 2010-11-27T12:10:00.000 | 0 | 0 | 0 | 0 | python,architecture,3d,pyglet | 4,368,817 | 2 | false | 0 | 1 | You could put the logic into a seperate module / into seperate classes/functions.
In my 2D-Game I have a GameLogic class which simplifies registering it's methods for certain events or scheduling them (and unregistering+unscheduling them), and I created a @state_wrapper decorator which injects a simple new-style object as state-storage for that method. If you do it like that you don't have to pass the pointer to all your world objects, only the event-methods have to get access to your objects.
But I wouldn't claim that this is the best solution ;) | 1 | 2 | 0 | This is a bit of a vague question but bear with me. I am in the process of writing a game using Python/Pyglet and openGL. I currently have it structured so that there is an object called 'world', in this are other objects with other objects inside them etc. I did it this way because for instance one part of the game is a platform with other objects on it, and when I tilt the platform I want the objects on it to tilt with it. So I do platform.draw() which calls glRotate, glTranslate, then draw each of the objects saving the modelview matrix inbetween, this way all the objects on the platform move together.
The first question is, is this a sensible way to organise things or should I be using some other method?
I don't have a camera class, currently I am just translating the whole world or parts of it to give the illusion of movement. However, in the future I want to be able to switch viewpoints between objects, so for instance switch from looking down onto the world from above to a 1st person view from one of the objects in the world. So the second question is what is the best way to structure my program so that this will be achievable in the future? | How to organise the structure of a 3D game? | 0 | 0 | 0 | 382 |
4,294,060 | 2010-11-27T21:41:00.000 | 0 | 0 | 0 | 0 | python,tkinter,py2app | 4,300,560 | 1 | true | 0 | 1 | Turns out it was a problem with using Snow Leopard. I tried it on a Leopard machine at school and it builds fine. | 1 | 2 | 0 | I have a Tkinter app written in python, and I want to make "native" (easy to run) mac and windows executables of it. I've successfully built a windows .exe using py2exe, but the equivalent process with py2app isn't working.
Here's my setup.py:
from setuptools import setup
import sys
MAIN_SCRIPT = "myapp.py"
WINDOWS_ICON = "myicon.ico"
MAC_ICON = "myicon.icns"
if sys.platform in ("win32", "win64"): # does win64 exist?
import py2exe
setup( windows=[{ "script":MAIN_SCRIPT,
"icon_resources":[(0x0004, WINDOWS_ICON)]
}],
)
elif sys.platform == "darwin":
import py2app
setup( app=[MAIN_SCRIPT], # doesn't include the icon yet
setup_requires=["py2app"],
)
I just cd to my app directory and run python setup.py py2app. The .app appears without errors, but it crashes on launch with "myapp has encountered a fatal error, and will now terminate."
I'm running Snow Leopard, and I've tried this with both the standard Apple Python 2.6 and python25 from MacPorts. I read somewhere that it's better to use a different Python because py2app won't bundle the system version in your app.
EDIT: Here's what the mac console has to say about it:
11/27/10 1:54:44 PM [0x0-0x80080].org.pythonmac.unspecified.myapp[77495] dlsym(0x10b120, Py_SetProgramName): symbol not found
11/27/10 1:54:46 PM [0x0-0x80080].org.pythonmac.unspecified.myapp[77495] 0x99274242
11/27/10 1:54:46 PM com.apple.launchd.peruser.501[185] ([0x0-0x80080].org.pythonmac.unspecified.myapp[77495]) Exited with exit code: 255 | Help building a mac application from python using py2app? | 1.2 | 0 | 0 | 1,470 |
4,295,384 | 2010-11-28T04:32:00.000 | 1 | 0 | 1 | 0 | python,types,syntax,django-templates | 4,296,635 | 5 | false | 1 | 0 | In addition to the points already posted, consider this. Python uses special member variables and functions to provide metadata about the object. Both the interpreter and programmers make heavy use of these. For example, both dicts and lists have a __len__ member function. Now, if a dict's data were accessed by using the . operator, a potential ambiguity arises if the dict has a key called __len__. You could special-case these, but many objects have a __dict__ attribute which is a mapping of member names and values. If that object happened to be a container, which also defined a __len__ attribute, you would end up with an utter mess.
Problems like this would end up turning Python into a mishmash of special cases that the programmer would have to constantly be aware of. This would detract from the reason why many people use Python in the first place, i.e., its elegant simplicity.
Now, consider that new users often shadow built-ins (if the code in SO questions is any indication) and having something like this starts to look like a really bad idea, since it would exacerbate the problem many-fold. | 5 | 1 | 0 | My karate instructor is fond of saying, "a block is a lock is a throw is a blow." What he means is this: When we come to a technique in a form, although it might seem to look like a block, a little creativity and examination shows that it can also be seen as some kind of joint lock, or some kind of throw, or some kind of blow.
So it is with the way the django template syntax uses the dot (".") character. It perceives it first as a dictionary lookup, but it will also treat it as a class attribute, a method, or list index - in that order. The assumption seems to be that, one way or another, we are looking for a piece of knowledge. Whatever means may be employed to store that knowledge, we'll treat it in such a way as to get it into the template.
Why doesn't python do the same? If there's a case where I might have assigned a dictionary term spam['eggs'], but know for sure that spam has an attribute eggs, why not let me just write spam.eggs and sort it out the way django templates do?
Otherwise, I have to except an AttributeError and add three additional lines of code.
I'm particularly interested in the philosophy that drives this setup. Is it regarded as part of strong typing? | Python syntax reasoning (why not fall back for . the way django template syntax does?) | 0.039979 | 0 | 0 | 225 |
4,295,384 | 2010-11-28T04:32:00.000 | 1 | 0 | 1 | 0 | python,types,syntax,django-templates | 4,296,043 | 5 | false | 1 | 0 | The different methods of accessing
attributes do different things. If
you have a function foo the two lines
of code
a = foo,
a = foo()
do two
very different things. Without
distinct syntax to reference and call
functions there would be no way for
python to know whether the variable
should be a reference to foo or the
result of running foo. The () syntax removes the ambiguity.
Lists and dictionaries are two very different data structures. One of the things that determine which one is appropriate in a given situation is how its contents can be accessed (key Vs index). Having separate syntax for both of them reinforces the notion that these two things are not the same and neither one is always appropriate.
It makes sense for these distinctions to be ignored in a template language, the person writing the html doesn't care, the template language doesn't have function pointers so it knows you don't want one. Programmers who write the python that drive the template however do care about these distinctions. | 5 | 1 | 0 | My karate instructor is fond of saying, "a block is a lock is a throw is a blow." What he means is this: When we come to a technique in a form, although it might seem to look like a block, a little creativity and examination shows that it can also be seen as some kind of joint lock, or some kind of throw, or some kind of blow.
So it is with the way the django template syntax uses the dot (".") character. It perceives it first as a dictionary lookup, but it will also treat it as a class attribute, a method, or list index - in that order. The assumption seems to be that, one way or another, we are looking for a piece of knowledge. Whatever means may be employed to store that knowledge, we'll treat it in such a way as to get it into the template.
Why doesn't python do the same? If there's a case where I might have assigned a dictionary term spam['eggs'], but know for sure that spam has an attribute eggs, why not let me just write spam.eggs and sort it out the way django templates do?
Otherwise, I have to except an AttributeError and add three additional lines of code.
I'm particularly interested in the philosophy that drives this setup. Is it regarded as part of strong typing? | Python syntax reasoning (why not fall back for . the way django template syntax does?) | 0.039979 | 0 | 0 | 225 |
4,295,384 | 2010-11-28T04:32:00.000 | 1 | 0 | 1 | 0 | python,types,syntax,django-templates | 4,297,020 | 5 | false | 1 | 0 | In addition to the responses above, it's not practical to merge dictionary lookup and object lookup in general because of the restrictions on object members.
What if your key has whitespace? What if it's an int, or a frozenset, etc.? Dot notation can't account for these discrepancies, so while it's an acceptable tradeoff for a templating language, it's unacceptable for a general-purpose programming language like Python. | 5 | 1 | 0 | My karate instructor is fond of saying, "a block is a lock is a throw is a blow." What he means is this: When we come to a technique in a form, although it might seem to look like a block, a little creativity and examination shows that it can also be seen as some kind of joint lock, or some kind of throw, or some kind of blow.
So it is with the way the django template syntax uses the dot (".") character. It perceives it first as a dictionary lookup, but it will also treat it as a class attribute, a method, or list index - in that order. The assumption seems to be that, one way or another, we are looking for a piece of knowledge. Whatever means may be employed to store that knowledge, we'll treat it in such a way as to get it into the template.
Why doesn't python do the same? If there's a case where I might have assigned a dictionary term spam['eggs'], but know for sure that spam has an attribute eggs, why not let me just write spam.eggs and sort it out the way django templates do?
Otherwise, I have to except an AttributeError and add three additional lines of code.
I'm particularly interested in the philosophy that drives this setup. Is it regarded as part of strong typing? | Python syntax reasoning (why not fall back for . the way django template syntax does?) | 0.039979 | 0 | 0 | 225 |
4,295,384 | 2010-11-28T04:32:00.000 | 6 | 0 | 1 | 0 | python,types,syntax,django-templates | 4,295,442 | 5 | true | 1 | 0 | JUST MY correct OPINION's opinion is indeed correct. I can't say why Guido did it this way but I can say why I'm glad that he did.
I can look at code and know right away if some expression is accessing the 'b' key in a dict-like object a, the 'b' attribute on the object a, a method being called on or the b index into the sequence a.
Python doesn't have to try all of the above options every time there is an attribute lookup. Imagine if every time one indexed into a list, Python had to try three other options first. List intensive programs would drag. Python is slow enough!
It means that when I'm writing code, I have to know what I'm doing. I can't just toss objects around and hope that I'll get the information somewhere somehow. I have to know that I want to lookup a key, access an attribute, index a list or call a method. I like it that way because it helps me think clearly about the code that I'm writing. I know what the identifiers are referencing and what attributes and methods I'm expecting the object of those references to support.
Of course Guido Van Rossum might have just flipped a coin for all I know (He probably didn't) so you would have to ask him yourself if you really want to know.
As for your comment about having to surround these things with try blocks, it probably means that you're not writing very robust code. Generally, you want your code to expect to get some piece of information from a dict-like object, list-like object or a regular object. You should know which way it's going to do it and let anything else raise an exception.
The exception to this is that it's OK to conflate attribute access and method calls using the property decorator and more general descriptors. This is only good if the method doesn't take arguments. | 5 | 1 | 0 | My karate instructor is fond of saying, "a block is a lock is a throw is a blow." What he means is this: When we come to a technique in a form, although it might seem to look like a block, a little creativity and examination shows that it can also be seen as some kind of joint lock, or some kind of throw, or some kind of blow.
So it is with the way the django template syntax uses the dot (".") character. It perceives it first as a dictionary lookup, but it will also treat it as a class attribute, a method, or list index - in that order. The assumption seems to be that, one way or another, we are looking for a piece of knowledge. Whatever means may be employed to store that knowledge, we'll treat it in such a way as to get it into the template.
Why doesn't python do the same? If there's a case where I might have assigned a dictionary term spam['eggs'], but know for sure that spam has an attribute eggs, why not let me just write spam.eggs and sort it out the way django templates do?
Otherwise, I have to except an AttributeError and add three additional lines of code.
I'm particularly interested in the philosophy that drives this setup. Is it regarded as part of strong typing? | Python syntax reasoning (why not fall back for . the way django template syntax does?) | 1.2 | 0 | 0 | 225 |
4,295,384 | 2010-11-28T04:32:00.000 | 7 | 0 | 1 | 0 | python,types,syntax,django-templates | 4,295,436 | 5 | false | 1 | 0 | django templates and python are two, unrelated languages. They also have different target audiences.
In django templates, the target audience is designers, who proabably don't want to learn 4 different ways of doing roughly the same thing ( a dictionary lookup ). Thus there is a single syntax in django templates that performs the lookup in several possible ways.
python has quite a different audience. developers actually make use of the many different ways of doing similar things, and overload each with distinct meaning. When one fails it should fail, because that is what the developer means for it to do. | 5 | 1 | 0 | My karate instructor is fond of saying, "a block is a lock is a throw is a blow." What he means is this: When we come to a technique in a form, although it might seem to look like a block, a little creativity and examination shows that it can also be seen as some kind of joint lock, or some kind of throw, or some kind of blow.
So it is with the way the django template syntax uses the dot (".") character. It perceives it first as a dictionary lookup, but it will also treat it as a class attribute, a method, or list index - in that order. The assumption seems to be that, one way or another, we are looking for a piece of knowledge. Whatever means may be employed to store that knowledge, we'll treat it in such a way as to get it into the template.
Why doesn't python do the same? If there's a case where I might have assigned a dictionary term spam['eggs'], but know for sure that spam has an attribute eggs, why not let me just write spam.eggs and sort it out the way django templates do?
Otherwise, I have to except an AttributeError and add three additional lines of code.
I'm particularly interested in the philosophy that drives this setup. Is it regarded as part of strong typing? | Python syntax reasoning (why not fall back for . the way django template syntax does?) | 1 | 0 | 0 | 225 |
4,295,482 | 2010-11-28T05:07:00.000 | 3 | 0 | 1 | 0 | python,multithreading | 4,296,669 | 1 | true | 0 | 0 | Can you tell which version of python you are using?
Maybe you could have posted a snippet too.
From Python 2.6, you have a timeout added in urllib2.urlopen.
Hope this will help you. It's from the python docs.
urllib2.urlopen(url[, data][,
timeout]) Open the URL url, which can
be either a string or a Request
object.
Warning HTTPS requests do not do any
verification of the server’s
certificate. data may be a string
specifying additional data to send to
the server, or None if no such data is
needed. Currently HTTP requests are
the only ones that use data; the HTTP
request will be a POST instead of a
GET when the data parameter is
provided. data should be a buffer in
the standard
application/x-www-form-urlencoded
format. The urllib.urlencode()
function takes a mapping or sequence
of 2-tuples and returns a string in
this format. urllib2 module sends
HTTP/1.1 requests with
Connection:close header included.
The optional timeout parameter
specifies a timeout in seconds for
blocking operations like the
connection attempt (if not specified,
the global default timeout setting
will be used). This actually only
works for HTTP, HTTPS and FTP
connections.
This function returns a file-like
object with two additional methods:
geturl() — return the URL of the
resource retrieved, commonly used to
determine if a redirect was followed
info() — return the meta-information
of the page, such as headers, in the
form of an mimetools.Message instance
(see Quick Reference to HTTP Headers)
Raises URLError on errors.
Note that None may be returned if no
handler handles the request (though
the default installed global
OpenerDirector uses UnknownHandler to
ensure this never happens).
In addition, default installed
ProxyHandler makes sure the requests
are handled through the proxy when
they are set.
Changed in version 2.6: timeout was
added. | 1 | 0 | 0 | I was trying to download images with multi-thread, which has a limited max_count in python.
Each time a download_thread is started, I leave it alone and activate another one. I hope the download process could be ended in 5s, which means downloading is failed if opening the url costs more than 5s.
But how can I know it and stop the failed thread??? | image download problem (python) | 1.2 | 0 | 0 | 350 |
4,295,823 | 2010-11-28T07:35:00.000 | 0 | 0 | 0 | 0 | c#,php,python,apache,nginx | 4,297,198 | 1 | false | 1 | 0 | Twisted network engine is about the best answer for you. What you can have is you can have the downloader serving a maximum of 100 x people then when the queue is full you will direct people to a holding loop, in the holding loop they will wait x seconds, check if queue is full, check not expired, see who else is waiting, if this ticket was here first, jump to top of download queue. As a TCP/IP connection comes in on twisted the level of control on your clients is so insane that you can do some might and powerful things in weird and wonderful ways, now imagine building this into a scalable and interactive twisted http server where you keep the level of control but you can actually serve resources.
The simplest way to get away with it is probably a pool of tickets, when a download is complete the downloader returns the ticket to the pool for someone else to take, if there are no tickets wait your turn. | 1 | 1 | 0 | My goal:
I want to host a folder of photos, but if at anytime 100 files are being downloaded, I want to redirect a new downloader/request to a 'waiting page' and give them a place in line and an approximate countdown clock until its their turn to download their requested content. Then either redirect them directly to the content, or (ideally) give them a button (token,expiring serial number) they can click that will take them to the content when they are ready.
I've seen sites do something similar to this, such as rapidshare, but I have not seen an open-source example of this type of setup. I would think it would be combining several technologies and modifying request headers?
Any help/ideas would be greatly appreciated! | Controlling rate of downloads on a per request and/or per resource basis (and providing a first-come-first-serve waiting system) | 0 | 0 | 1 | 62 |
4,296,138 | 2010-11-28T09:15:00.000 | -1 | 0 | 1 | 1 | python,path,wildcard | 38,177,861 | 8 | false | 0 | 0 | iglob is better than glob here since you do not actually want the full list of rar files, but just want to check that one rar exists | 1 | 58 | 0 | I'd like to check if there are any .rar files in a directory. It doesn’t need to be recursive.
Using wildcard with os.path.isfile() was my best guess, but it doesn't work. What can I do then? | Use wildcard with os.path.isfile() | -0.024995 | 0 | 0 | 80,871 |
4,296,830 | 2010-11-28T12:56:00.000 | 2 | 0 | 0 | 1 | python,google-app-engine | 4,300,033 | 1 | true | 1 | 0 | 'Offline' requests such as Task Queue tasks and Cron jobs have no 'user' as far as systems like SDC are concerned. If your SDC connection requires a logged in user, you will not be able to access it from a cron/task queue job. | 1 | 1 | 0 | Is it possible to use the Secure Data Connector (SDC) to access internal resources in Tasks/Cron Jobs on the Google AppEngine?
The documentation speaks about the currently logged in user but does not further elaborate this scenario. | GAE - Secure data Connector and Taskqueue/Cron | 1.2 | 0 | 0 | 236 |
4,297,167 | 2010-11-28T14:20:00.000 | -2 | 0 | 1 | 0 | python,c,module,numpy,cython | 4,297,263 | 2 | false | 0 | 0 | Check your Python documentation, the section "Python/C API Reference Manual" describes in detail how to do it.
EDITED:
So what you want is porting a 2.x lib to 3.x. That's a big work to do.
If the solution your wished exists. Python 2.x should have been eliminated by now.
Sure there is a 2to3 tool. But a Python lib written by C is not applicable in this way.
So, you may follow the instruction in the "Python/C API Reference Manual" to port the lib to 3.x or just wait. | 1 | 6 | 0 | Is it possible to import arbitrary modules in cython, compile them to shared object files and then use them in python 3.1?
The reason for this is, that I am writing an extension for the program "blender", which has an internal python 3.1 interpreter. But i would also like to make use of some python-modules which are not ported to 3.x, yet
I have specifically numpy in my mind (but also some other libraries). I have a module, which makes use of numpy. As I want to redistribute that module, I don't want poeple to install numpy on their machines. would that work? | using cython to port modules to python 3.1 | -0.197375 | 0 | 0 | 607 |
4,297,672 | 2010-11-28T16:12:00.000 | 4 | 0 | 0 | 0 | python,sqlite,full-text-search,sqlalchemy,pylons | 4,297,732 | 6 | false | 1 | 0 | "Sphinx does not have a Python API"
is not true. Download the release and look at sphinx/api/sphinxapi.py
I use it myself and I'm pretty happy with it. The documentation is for PHP only but the Python API uses the exact same names for all functions. | 3 | 7 | 0 | I'm searching for a Python full text search engine.
I took a look at PyLucense, but I think that using a Java-based library in a Python project is not good. As I understand, Sphinx does not have a Python API.
Any ideas ? | Full text search engine for Python | 0.132549 | 0 | 0 | 10,456 |
4,297,672 | 2010-11-28T16:12:00.000 | 2 | 0 | 0 | 0 | python,sqlite,full-text-search,sqlalchemy,pylons | 4,297,754 | 6 | false | 1 | 0 | I will recommend whoosh. You can easy install it ie easy_install Whoosh
It has a neat API too | 3 | 7 | 0 | I'm searching for a Python full text search engine.
I took a look at PyLucense, but I think that using a Java-based library in a Python project is not good. As I understand, Sphinx does not have a Python API.
Any ideas ? | Full text search engine for Python | 0.066568 | 0 | 0 | 10,456 |
4,297,672 | 2010-11-28T16:12:00.000 | 2 | 0 | 0 | 0 | python,sqlite,full-text-search,sqlalchemy,pylons | 4,297,894 | 6 | false | 1 | 0 | Particularly for full text search, Solr is an excellent choice. You will have a hard time finding a more widely used and more open choice. We use Solr/Lucene at my company with a PHP web application being the client and the HTTP/REST API to let you query the index. It has as much functionality as a native PHP client would have and much more flexibility out of the box. You can perform any query/filter you choose all using the REST API. But, on top of all of that, you get an extremely performant and widely used search system with built-in replication that is constantly being improved. Strongly recommend Solr 1.4.x as your starting point. | 3 | 7 | 0 | I'm searching for a Python full text search engine.
I took a look at PyLucense, but I think that using a Java-based library in a Python project is not good. As I understand, Sphinx does not have a Python API.
Any ideas ? | Full text search engine for Python | 0.066568 | 0 | 0 | 10,456 |
4,298,011 | 2010-11-28T17:28:00.000 | 0 | 0 | 0 | 0 | python,django,django-models | 4,458,226 | 1 | true | 1 | 0 | you can overwrite your model's save() by adding codes to create the object directly if it doesn't exist. | 1 | 0 | 0 | I'm using raw_id_fields in my admin.py to change the ForeignKey's select box to an input box.
When saving the form, it checks if the object that I wrote in the ForeignKey box exists, if not, it raises an error saying "Select a valid choice. That choice is not one of the available choices."
What I want to do is skipping this validation and creating the object directly if it doesn't exist.
Any idea to do that?
Thank you very much | force creating object when using raw_id_fields in Django | 1.2 | 0 | 0 | 187 |
4,298,073 | 2010-11-28T17:41:00.000 | 1 | 0 | 1 | 0 | python,configparser | 4,298,145 | 3 | false | 0 | 0 | Mine works fine.
And noticed "Lines beginning with '#' or ';' are ignored and may be used to provide comments.
" | 1 | 2 | 0 | I need to specify a password on the right side of the equals sign in a Python configparser file, but semicolon is the comment character.
Escaping with \ does not work.
How can I pass the string "foo;" as a value in configparser? | How do I put a semicolon in a value in Python configparser? | 0.066568 | 0 | 0 | 2,384 |
4,298,260 | 2010-11-28T18:26:00.000 | 0 | 0 | 1 | 0 | python,debugging,multiprocessing | 4,361,057 | 3 | false | 0 | 0 | Rather than starting your function or class via Process, just call it directly and debug as you normally would. | 2 | 4 | 0 | What I would like is to be able to step-debug code that runs in a separate process using the multiprocessing package.
I remember looking for a solution about a year ago and not finding one. I was told to just do a lot of logging, but of course it is an inferior method. So maybe someone came up with a solution in the meantime? For example, some mechanism for making the newly-spawned process connect with the debugger? | Is there a way to debug Python code which runs on a `multiprocessing.Process`? | 0 | 0 | 0 | 1,362 |
4,298,260 | 2010-11-28T18:26:00.000 | 1 | 0 | 1 | 0 | python,debugging,multiprocessing | 4,298,409 | 3 | false | 0 | 0 | You could start the process You need to debug manually, without using the Process interface on this process. | 2 | 4 | 0 | What I would like is to be able to step-debug code that runs in a separate process using the multiprocessing package.
I remember looking for a solution about a year ago and not finding one. I was told to just do a lot of logging, but of course it is an inferior method. So maybe someone came up with a solution in the meantime? For example, some mechanism for making the newly-spawned process connect with the debugger? | Is there a way to debug Python code which runs on a `multiprocessing.Process`? | 0.066568 | 0 | 0 | 1,362 |
4,298,622 | 2010-11-28T19:35:00.000 | 1 | 0 | 0 | 0 | python,ruby-on-rails,ruby,django | 4,298,758 | 5 | false | 1 | 0 | This is a question I still am trying to find the answer too, here is what i can tell you so far.
Preface
When it comes to scripting langauges I always prefer python, not only I feel more strong using python, but also the libraries are better and work faster. Also (and ruby devs will have something to say) I find Python a more understandable and readable code that Ruby.
Said this, Rails is an excellent framework! It has a lot more "magic" that Django, and now with Rails 3 you can write your ajax in unobtrusive Javascript which makes it beautiful to read. Also the path and form features are far better that Django's.
The big problem is this: As I said Rails does a lot for you (aka magic), the only problems is that if you want to escape those conventions for some reason you find yourself dealing with lots of problems, while with Django you have more control over your application.
Django also has the super-hardcore Admin and User application, no need to install any plugin, this is ALL done for you! Setting up users is incredibly easy and the Admin backend gives you CRUD for every model.
Overall I prefer Django, I understand it better and it does what I say, although I must say that, as far as things are going nowadays, Rails will have more support in the future.
Feel free to ask any question!! Hope it helped
Dan | 2 | 6 | 0 | I have around 2 Weeks of Real development time to churn out a contact database system to replace various spreadsheets and pieces of paper laying around.
Also I need to develop two websites (with dynamic content) and a small AJAXian web service.
I have no experience of rails or django, but I can learn fast.
Both claim to be all about the fast development.
What is it that rails has that django doesn't have and vice versa that would accelerate the development of this application?
Also the contact database benifit more from the admin panel (dj) or the scaffolding of views (ror)?
(there will be a lot of CRUD operations) | Faster Development Rails or Django? | 0.039979 | 0 | 0 | 3,565 |
4,298,622 | 2010-11-28T19:35:00.000 | 8 | 0 | 0 | 0 | python,ruby-on-rails,ruby,django | 4,298,635 | 5 | false | 1 | 0 | The Django admin will generate a CRUD application that you can customize to suit almost any need, from your model definitions. I've used the admin for the main user interface for several projects and can tell you that it is a real timesaver. You don't have to spend any time whatsoever at writing templates or Javascript.
Django also has generic views which can do object detail, list views, update or delete on any model without you worrying about the logic of the app. You just supply the templates, hook into the urls and you're basically done.
For deployment I'd say Django and Rails are now equal. Rails has been painful to deploy, but things have changed greatly.
For a simple contact database the admin might be the biggest difference between Rails and Django. And the fact that you can run your Django project locally, with a real webserver without any configuration ('python manage.py runserver'). | 2 | 6 | 0 | I have around 2 Weeks of Real development time to churn out a contact database system to replace various spreadsheets and pieces of paper laying around.
Also I need to develop two websites (with dynamic content) and a small AJAXian web service.
I have no experience of rails or django, but I can learn fast.
Both claim to be all about the fast development.
What is it that rails has that django doesn't have and vice versa that would accelerate the development of this application?
Also the contact database benifit more from the admin panel (dj) or the scaffolding of views (ror)?
(there will be a lot of CRUD operations) | Faster Development Rails or Django? | 1 | 0 | 0 | 3,565 |
4,298,886 | 2010-11-28T20:24:00.000 | 2 | 0 | 0 | 0 | python,sqlalchemy,pylons,sqlalchemy-migrate | 4,300,116 | 1 | true | 0 | 0 | Well what format is your seed data starting out in? The migrate calls are just python methods so you're free to open some csv, create SA object instances, loop, etc. I usually have my seed data as a series of sql insert statements and just loop over them executing a migate.execute(query) for each one.
So I'll first create the table, loop and run seed data, and then empty/drop table on the downgrade method. | 1 | 2 | 0 | I'm using SqlAlchemy in my Pylons application to access data and SqlAlchemy-migrate to maintain the database schema.
It works fine for managing the schema itself. However, I also want to manage seed data in a migrate-like way. E.g. when ProductCategory table is created it would make sense to seed it with categories data.
Looks like SqlAlchemy-migrate does not support this directly. What would be a good approach to do this with Pylons+SqlAlchemy+SqlAlchemy-migrate? | Managing seed data with SqlAlchemy and SqlAlchemy-migrate | 1.2 | 1 | 0 | 2,454 |
4,299,293 | 2010-11-28T21:50:00.000 | 2 | 0 | 1 | 0 | python,string | 4,299,374 | 3 | false | 0 | 0 | Strictly speaking, you cannot modify strings in python at all. Strings are an immutable type. If it is sufficient for your needs to return new strings with the desired modification, then the other answers do just that. If you really need a mutable type, you can use a list of single character strings, or you can use the array module's array.fromstring() or array.fromunicode() methods, or in newer python versions, the bytearray type. | 1 | 2 | 0 | I have a string here in python '#b9d9ff'. How do I remove the hash symbol (#)? | Modifying strings in Python | 0.132549 | 0 | 0 | 3,394 |
4,299,324 | 2010-11-28T21:55:00.000 | 0 | 0 | 0 | 0 | python,cdn | 18,712,080 | 2 | false | 1 | 0 | I think you are trying to upload the static content of your website (not the user uploaded files) to CDN via FTP client or something similar.
To achieve bulk upload you may ZIP all such files on local machine and upload to your webserver. Unzip files on webserver and write a batch script which utlize the CDN API to send files in CDN container.
For fulture new or modified files, write another batch script to grab all new/modified files and send to CDN container via CDN API. | 1 | 0 | 0 | I have to upload a webpage on cdn. Say test.html, test.css, image1.jpg etc. Now I am uploading all these file one by one. I think which is not efficient. So, is it possible to keep all these files in folder and then upload this folder on the cdn? If yes, then what parameters i need to take care about that. Does zipping the folder helpful? I am using python.
Thanks in Advance | How to upload multiple files on cdn? | 0 | 0 | 1 | 1,114 |
4,299,432 | 2010-11-28T22:15:00.000 | 2 | 0 | 0 | 0 | python,tkinter | 64,151,502 | 6 | false | 0 | 1 | My solution is root.focus() it will remove widget focus. | 2 | 11 | 0 | I'd like to remove focus from a widget manually. | In Tkinter how do i remove focus from a widget? | 0.066568 | 0 | 0 | 16,266 |
4,299,432 | 2010-11-28T22:15:00.000 | 5 | 0 | 0 | 0 | python,tkinter | 47,823,400 | 6 | false | 0 | 1 | Set focus to another widget to remove focus from the target widget is a good idea. There are two methods for this: w.focus_set() and w.focus_force(). However, method w.focus_force() is impolite. It's better to wait for the window manager to give you the focus. Setting focus to parent widget or to the root window removes focus from the target widget.
Some widgets have takefocus option. Set takefocus to 0 to take your widget out of focus traversal (when user hits <Tab> key). | 2 | 11 | 0 | I'd like to remove focus from a widget manually. | In Tkinter how do i remove focus from a widget? | 0.16514 | 0 | 0 | 16,266 |
4,299,769 | 2010-11-28T23:31:00.000 | 0 | 0 | 0 | 0 | python,django,pinax,profiles | 5,870,229 | 3 | false | 1 | 0 | I generally like starting with the basic or account, then build up to what I need. I prefer this method to starting with complete/social and stripping out what I don't need. Just fyi. | 2 | 2 | 0 | I want a "settings" page where the
user can submit his
hometown/biography/email settings and upload his avatar
We will be building a mobile app that uses HTTP Rest API to update the user's profile, so we must be able to do manual override of these apps.
That's it! I don't want anything else. I don't care about the friending or blogging or anything.
Which Django App should I use? Currently, I am using Pinax's basic_project. | Which Django/Pinax app should I use? There are so many, and I just want the simplest one | 0 | 0 | 0 | 491 |
4,299,769 | 2010-11-28T23:31:00.000 | 1 | 0 | 0 | 0 | python,django,pinax,profiles | 4,510,829 | 3 | false | 1 | 0 | I actually am approaching the same problem.
I find overriding the pinax profile app is enough. The profile section is what allows the upload of avatars and your info and allows you to also edit it.
I still haven't found a good way to override the native apps yet. Right now I am copying over the app.
Thanks,
Ray | 2 | 2 | 0 | I want a "settings" page where the
user can submit his
hometown/biography/email settings and upload his avatar
We will be building a mobile app that uses HTTP Rest API to update the user's profile, so we must be able to do manual override of these apps.
That's it! I don't want anything else. I don't care about the friending or blogging or anything.
Which Django App should I use? Currently, I am using Pinax's basic_project. | Which Django/Pinax app should I use? There are so many, and I just want the simplest one | 0.066568 | 0 | 0 | 491 |
4,299,802 | 2010-11-28T23:37:00.000 | 23 | 0 | 1 | 0 | python,encoding | 4,299,809 | 4 | true | 0 | 0 | Instead of .encode('utf-8'), use .encode('latin-1'). | 2 | 21 | 0 | I feel stacked here trying to change encodings with Python 2.5
I have XML response, which I encode to UTF-8: response.encode('utf-8'). That is fine, but the program which uses this info doesn't like this encoding and I have to convert it to other code page. Real example is that I use ghostscript python module to embed pdfmark data to a PDF file - end result is with wrong characters in Acrobat.
I've done numerous combinations with .encode() and .decode() between 'utf-8' and 'latin-1' and it drives me crazy as I can't output correct result.
If I output the string to a file with .encode('utf-8') and then convert this file from UTF-8 to CP1252 (aka latin-1) with i.e. iconv.exe and embed the data everything is fine.
Basically can someone help me convert i.e. character á which is UTF-8 encoded as hex: C3 A1 to latin-1 as hex: E1?
Thanks in advance | Python: convert string from UTF-8 to Latin-1 | 1.2 | 0 | 1 | 144,526 |
4,299,802 | 2010-11-28T23:37:00.000 | 0 | 0 | 1 | 0 | python,encoding | 32,096,180 | 4 | false | 0 | 0 | If the previous answers do not solve your problem, check the source of the data that won't print/convert properly.
In my case, I was using json.load on data incorrectly read from file by not using the encoding="utf-8". Trying to de-/encode the resulting string to latin-1 just does not help... | 2 | 21 | 0 | I feel stacked here trying to change encodings with Python 2.5
I have XML response, which I encode to UTF-8: response.encode('utf-8'). That is fine, but the program which uses this info doesn't like this encoding and I have to convert it to other code page. Real example is that I use ghostscript python module to embed pdfmark data to a PDF file - end result is with wrong characters in Acrobat.
I've done numerous combinations with .encode() and .decode() between 'utf-8' and 'latin-1' and it drives me crazy as I can't output correct result.
If I output the string to a file with .encode('utf-8') and then convert this file from UTF-8 to CP1252 (aka latin-1) with i.e. iconv.exe and embed the data everything is fine.
Basically can someone help me convert i.e. character á which is UTF-8 encoded as hex: C3 A1 to latin-1 as hex: E1?
Thanks in advance | Python: convert string from UTF-8 to Latin-1 | 0 | 0 | 1 | 144,526 |
4,301,681 | 2010-11-29T07:27:00.000 | 1 | 1 | 1 | 0 | python,tox | 4,301,739 | 5 | true | 0 | 0 | You could just install a Python 2.5.2.
I have 3 different versions Python installed on my Lucid and they use different links under /bin/ so it's easy to call the specific version
python -> python3 ->python3.1
python2 -> python2.7
python2.5 | 2 | 2 | 0 | I currently have Python 2.6.2 installed on my mac. I am writing a script which MUST run on Python 2.5.2. So I want to write a python script, and test is specifically against 2.5.2 and NOT 2.6.2.
I was looking at virtualenv, but it doesn't seem to solve my problem. I ran python virtualenv.py TEST which made a TEST dir, but it had python 2.6 in it. Is there a way to make virtualenv use a different version of python than what's installed default on my machine? Is another way to use the #! as the first line of the python script? How would I do that? | Testing a python script in a specific version | 1.2 | 0 | 0 | 4,321 |
4,301,681 | 2010-11-29T07:27:00.000 | 0 | 1 | 1 | 0 | python,tox | 4,301,698 | 5 | false | 0 | 0 | try #!/path/to/your/python/version
But make sure you execute the script from the terminal, and make it executable before hand: chmod 755 myscript.py | 2 | 2 | 0 | I currently have Python 2.6.2 installed on my mac. I am writing a script which MUST run on Python 2.5.2. So I want to write a python script, and test is specifically against 2.5.2 and NOT 2.6.2.
I was looking at virtualenv, but it doesn't seem to solve my problem. I ran python virtualenv.py TEST which made a TEST dir, but it had python 2.6 in it. Is there a way to make virtualenv use a different version of python than what's installed default on my machine? Is another way to use the #! as the first line of the python script? How would I do that? | Testing a python script in a specific version | 0 | 0 | 0 | 4,321 |
4,303,851 | 2010-11-29T12:49:00.000 | 0 | 0 | 1 | 0 | c++,python,3d | 4,303,972 | 8 | false | 0 | 1 | I would implement the time-critical stuff as 3D and its object handling + rendering in raw C/C++ and let an embedded Python with external modules handle the game logic (object movement, object properties, scripting and so on). | 3 | 15 | 0 | So we want to program a 3d game for school, we can probably use blender for the 3d models, however we are totally clueless as to how to use them in a game/application.
Are there any recommended guides/documents we should read on general 3d game programming and perhaps python specific stuff.
We are also possibly considering programming it in C++ but for now I think it's easier to use Python as we can fully focus on the 3d mechanics that way. | 3d game with Python, starting from nothing | 0 | 0 | 0 | 56,291 |
4,303,851 | 2010-11-29T12:49:00.000 | 2 | 0 | 1 | 0 | c++,python,3d | 4,303,913 | 8 | false | 0 | 1 | If you want to write a 3D game you might want to start by understanding the basics of programming and computer science. Starting with the top and learning a language, then find yourself a good graphics library for example Panda, Pygame are all good choices, then there are other parts to consider like networking with twisted for example or a physics engine. It might also be a good choice to consider using a working engine like the unreal engine as often game designers get too wrapped up in game mechanics and not the game itself | 3 | 15 | 0 | So we want to program a 3d game for school, we can probably use blender for the 3d models, however we are totally clueless as to how to use them in a game/application.
Are there any recommended guides/documents we should read on general 3d game programming and perhaps python specific stuff.
We are also possibly considering programming it in C++ but for now I think it's easier to use Python as we can fully focus on the 3d mechanics that way. | 3d game with Python, starting from nothing | 0.049958 | 0 | 0 | 56,291 |
4,303,851 | 2010-11-29T12:49:00.000 | 2 | 0 | 1 | 0 | c++,python,3d | 4,304,000 | 8 | false | 0 | 1 | You should be aware that 3D game consists of
animated 3D models
3D environment (including NPCs and objects)
simulation of interaction between the environment and the models (game logic and game mechanics)
user interface (starting, saving and game settings)
The game logic and mechanics is going to usually the biggest and most complicated part and you should try to wrap your head against that first.
Modeling 3D objects and environment should be much easier after that. | 3 | 15 | 0 | So we want to program a 3d game for school, we can probably use blender for the 3d models, however we are totally clueless as to how to use them in a game/application.
Are there any recommended guides/documents we should read on general 3d game programming and perhaps python specific stuff.
We are also possibly considering programming it in C++ but for now I think it's easier to use Python as we can fully focus on the 3d mechanics that way. | 3d game with Python, starting from nothing | 0.049958 | 0 | 0 | 56,291 |
4,303,897 | 2010-11-29T12:54:00.000 | 3 | 0 | 0 | 0 | python,django | 4,303,960 | 2 | false | 1 | 0 | There is no sane way to get the user outside of the request. If the current user matters then pass it to any functions that need it. | 1 | 6 | 0 | I'm working on a medium sized project in django and i want to be able to access the current user from within my query manager. I need to be able to design a custom manager to limit the results and querysets so that the current user only get's information related to him/her.
I've received a few suggestions, I've also seen the not so supported example of using threadlocals from a django middleware. However, i'm very confused as this seems to be most promising solution now. I am looking for a better way to do this, so i can gain access to the current user from within a model manager. | How can i access the current user outside a request in django | 0.291313 | 0 | 0 | 7,107 |
4,304,899 | 2010-11-29T14:57:00.000 | 0 | 0 | 0 | 0 | python,django,django-models | 4,304,999 | 1 | true | 1 | 0 | As the currency rates change, you should either do it via javascript or (I would recommend) doing it in your view function. Storing it in a database would not make much sense, as the conversion rates change from day to day, and every time they changed, you would have to update the values in the database. If data is likely to change regularly, and can be easily generated dynamically, then that is the best option. | 1 | 1 | 0 | I have a quick question, more theory then actual code. I am building a small program that will interact with activeCollab. Anyways, I want to store the value of a quote in canadian dollars but I want to also be able to view it as USD as well. My question is, should I create a field to store the american price or should I use some sort of javascript to show the conversion on the fly (with the use of a button or something). Has anyone come across the same sort of issue before?
Thanks everyone.
Steve | Currency Conversion in django | 1.2 | 0 | 0 | 732 |
4,305,070 | 2010-11-29T15:16:00.000 | 0 | 1 | 0 | 1 | php,python | 4,305,158 | 4 | false | 0 | 0 | I think you should implement a web service . I don't know how to do it with python but i suppose it would be fairly easy. | 1 | 1 | 0 | I have a Python application (command line tool running on a machine M1) that has input I1 and output O2. Also, I have a PHP application (website running on a machine M2) that feeds the Python application with input I1 and expects to read the output O1. My question is what's the best approach to solve this problem? (the environment is GNU/Linux)
I was thinking at a solution with ssh; the PHP script executes a command via ssh: "ssh M2:./my_script.py arguments output_file" and transfers the output file "scp M2:output_file ." from M2 to M1. But, I don't think this solution is elegant. I was thinking of web services (the Python application should expose a web service), but I'm not sure what's the complexity of this solution or if it works.
Thanks, | PHP and Python interfacing | 0 | 0 | 0 | 354 |
4,305,512 | 2010-11-29T16:00:00.000 | 1 | 0 | 1 | 0 | python,setuptools,distribute | 4,315,782 | 1 | false | 0 | 0 | If you're using Python 2.4 on Windows, there aren't any advantages to using Distribute over Setuptools. Distribute only offers a comparative advantage on Python 2.6 (where it supports the new "home" directory layout) and Python 3.x (which setuptools hasn't been ported to).
Apart from that, there aren't really any "upgrades" in Distribute, relative to setuptools; in fact, Distribute still contains bugs that have either been fixed in setuptools, or that never existed in setuptools (because they were added in Distribute).
You should also be aware that the people who created Distribute are now mainly working on Distutils2, and are NOT planning any significant improvements to Distribute.
I realize this might not be the answer you're looking for, since apparently you've already decided to switch. However, if you switched purely on the basis of the popular rumor that setuptools isn't maintained or has bugs that Distribute fixes (which is actually the other way around), you might want to reconsider. | 1 | 0 | 0 | Our large python project is being upgraded from using the legacy "setuptools" project to use "distribute" as a drop-in replacement.
We've noticed one problematic difference between the two applications: In setuptools an egg which had an undefined zip-safe flag was assumed to be zip-safe and would install as a zipped file (unless the user explicitly specifies not to).
By comparison with the new Distribute all eggs are assumed to be not zip safe (and will install unzipped) unless they have the zip-safe flag set to be explictly True.
As a consequence eggs which would previously have been installed simply by copying the .egg file to the site-packages are now unzipped to site-packages. Ideally, I'd like the new distribute to install eggs in a manner which is exactly consistent with the older setuptools.
It may sound like an inconsequential thing, however if we change something as fundamental as the directory structure of the site-packages folder it will force our team to go through a phase of international UAT which will be very time-consuming. It would be far better if we could simply guarantee that the new installer produces the exact same directory structure as the old one.
FYI, I'm using the very latest distribute on Python 2.4.4 for Windows XP 32bit. | Is it possible to make eggs with a None zip-safe flag default to being instaleld zipped with Distribute? | 0.197375 | 0 | 0 | 870 |
4,307,433 | 2010-11-29T19:49:00.000 | 3 | 0 | 0 | 0 | python,django | 4,307,510 | 6 | false | 1 | 0 | When trying to assign a value to reserved keywords, SyntaxError is raised. | 3 | 0 | 0 | I seem to get a TypeError ('message' is an invalid keyword argument for this function) every time I try adding something in the DB via the Django admin interface. The object is added but this exception is raised. Could be this linked to the fact that I have a model named "Message"? | Is "message" a reserved word in Django or Python? | 0.099668 | 0 | 0 | 1,065 |
4,307,433 | 2010-11-29T19:49:00.000 | 1 | 0 | 0 | 0 | python,django | 4,307,715 | 6 | false | 1 | 0 | That means the function you are calling does not accept an argument named "message".
I guess that's because the model your are using doesn't have a field named "message" | 3 | 0 | 0 | I seem to get a TypeError ('message' is an invalid keyword argument for this function) every time I try adding something in the DB via the Django admin interface. The object is added but this exception is raised. Could be this linked to the fact that I have a model named "Message"? | Is "message" a reserved word in Django or Python? | 0.033321 | 0 | 0 | 1,065 |
4,307,433 | 2010-11-29T19:49:00.000 | 5 | 0 | 0 | 0 | python,django | 4,307,494 | 6 | true | 1 | 0 | No. Python's reserved words do not include message and the TypeError you've described doesn't suggest a namespace collision. Look at the function's keyword arguments and make sure that message is among them. It isn't though, so maybe you meant to type msg. | 3 | 0 | 0 | I seem to get a TypeError ('message' is an invalid keyword argument for this function) every time I try adding something in the DB via the Django admin interface. The object is added but this exception is raised. Could be this linked to the fact that I have a model named "Message"? | Is "message" a reserved word in Django or Python? | 1.2 | 0 | 0 | 1,065 |
4,308,346 | 2010-11-29T21:36:00.000 | 0 | 0 | 0 | 0 | python,pygtk,twisted,gtk | 4,310,711 | 2 | false | 0 | 1 | Threads, perhaps? The Twisted reactor joins all threads on shutdown, and if you're doing something in a callInThread that hangs, your loop may be unable to stop. (I'm not sure what the behavior would be if you're starting your own threads, either.) | 1 | 1 | 0 | Using Python 2.6, Twisted 10.1, and GTK+ 2.22, with latest pygtk installed, I'm having problems on shutdown. When I close my application and shut down the reactor (using the gtk2reactor of course), the application simply freezes.
I've poked around the twisted source and added debug messages. What ends up happening is, the 'shutdown' event fires, PortableGtkReactor.crash is called, which calls gtk.main_quit. The event gets processed at the end of ReactorBase.runUntilCurrent. When the function returns, control goes to ReactorBase.iterate, which returns control to PortableGtkReactor.simulate, which goes back to... the gtk.main() call. It looks like gtk just doesn't quit.
Unfortunately, when I put together a very simple example with twisted and the gtk "Hello World" sample, everything shut down correctly. It must be something my application is doing. Until I can figure it out further, though...
What might be causing this? Like what could an app do that causes gtk to not quit? The app worked fine on Gtk 2.12, with Python 2.5 and Twisted 8.1, if that helps at all. | Twisted + Gtk - shutdown not working properly | 0 | 0 | 0 | 426 |
4,308,790 | 2010-11-29T22:35:00.000 | 0 | 0 | 1 | 0 | python,function | 4,308,836 | 2 | false | 0 | 0 | I don't completely understand what you're after, but does the operator module (in the standard library) help at all? It defines functions for all the standard arithmetic operators. | 1 | 6 | 0 | I'm searching for a library that will let me manipulate functions with the standard operators (*, -, *, /, etc.).
Lets suppose you have a function f(x) = x ** 2 and g(x) = x + 2. I'd like to be able to write f * g and get a new functor that is essentialy x ** 2 * (x + 2) or f(g) and get (x + 2) ** 2.
I know this is not too hard to implement, you'll just have to make a Functor class and overload it's __call__ function, but I'm hoping there is a 3rd party library for it.
I'm not trying to use this for anything heavyweight just for learning. Thanks for the help. | Function arithmetic library for python | 0 | 0 | 0 | 733 |
4,311,347 | 2010-11-30T07:10:00.000 | 2 | 0 | 0 | 0 | python | 4,311,727 | 4 | true | 0 | 0 | If the script runs on your server, its purpose is to serve a document, not to download it (the latter would be the urllib solution).
Depending on your needs you can:
Set up static file serving with e.g. Apache
Make the script execute on a certain URL (e.g. with mod_wsgi), then the script should set the Content-Type (provides document type such as "text/plain") and Content-Disposition (provides download filename) headers and send the document data
As your question is not more specific, this answer can't be either. | 3 | 0 | 0 | I am writing a script which will run on my server. Its purpose is to download the document. If any person hit the particular url he/she should be able to download the document. I am using urllib.urlretrieve but it download document on the server side not on the client. How to download in python at client side? | how to download in python | 1.2 | 0 | 1 | 322 |
4,311,347 | 2010-11-30T07:10:00.000 | 1 | 0 | 0 | 0 | python | 4,311,383 | 4 | false | 0 | 0 | If the document is on your server and your intention is that the user should be able to download this file, couldn't you just serve the url to that resource as a hyperlink in your HTML code. Sorry if I have been obtuse but this seems the most logical step given your explanation. | 3 | 0 | 0 | I am writing a script which will run on my server. Its purpose is to download the document. If any person hit the particular url he/she should be able to download the document. I am using urllib.urlretrieve but it download document on the server side not on the client. How to download in python at client side? | how to download in python | 0.049958 | 0 | 1 | 322 |
4,311,347 | 2010-11-30T07:10:00.000 | 1 | 0 | 0 | 0 | python | 4,311,378 | 4 | false | 0 | 0 | Set the appropriate Content-type header, then send the file contents. | 3 | 0 | 0 | I am writing a script which will run on my server. Its purpose is to download the document. If any person hit the particular url he/she should be able to download the document. I am using urllib.urlretrieve but it download document on the server side not on the client. How to download in python at client side? | how to download in python | 0.049958 | 0 | 1 | 322 |
4,312,197 | 2010-11-30T09:29:00.000 | 11 | 0 | 1 | 0 | python,url | 4,312,223 | 3 | false | 0 | 0 | urllib.unquote is for replacing %xx escape codes in URLs with the characters they represent. It won't be useful for this.
Your "simple string replace stuff" is probably the best solution. | 1 | 4 | 0 | I have got a url in this form - http:\\/\\/en.wikipedia.org\\/wiki\\/The_Truman_Show. How can I make it normal url. I have tried using urllib.unquote without much success.
I can always use regular expressions or some simple string replace stuff. But I believe that there is a better way to handle this... | Python unescape URL | 1 | 0 | 1 | 8,233 |
4,312,966 | 2010-11-30T11:00:00.000 | 1 | 0 | 1 | 0 | .net,visual-studio-2010,ironpython | 6,151,868 | 4 | false | 0 | 0 | SharpDevelop has an IronPython - "Class Library" template for creating IronPython dlls. | 1 | 4 | 0 | I can see Console Application , WPF, WinForm, something else
But there is no Library, I need just a library .
How can I trick it ? Or there is no way to create library with Iron Python ? | How to create Library project | 0.049958 | 0 | 0 | 2,034 |
4,312,995 | 2010-11-30T11:02:00.000 | 0 | 0 | 0 | 0 | python,django | 4,313,083 | 2 | false | 1 | 0 | You might find some use in the functions activate(language) and deactivate(language) located in django.utils.translation. I'm not sure about the efficiency of this, I imagine it is slow, but it might do the job :) | 1 | 0 | 0 | I would like to notify the user in case he's viewing the site in a language that doesn't correspond to his first preference in the ACCEPT_LANGUAGE header.
For this reason I would like to present the message to the user in his first prefered language rather than the one he's currently viewing the web-site.
Is it possible with django (views and templates) to translate a string in a specific language indipendently than the current language?
Thanks
Example:
Italian user visits for the first time the site, but the english version.
I want him to see a message in italian like: "Preferiresti vedere il sito in Italiano?" | Django: translate in a different language than current language | 0 | 0 | 0 | 335 |
4,313,782 | 2010-11-30T12:33:00.000 | 1 | 1 | 0 | 0 | python,compilation,lxml | 4,327,797 | 2 | false | 0 | 0 | My solution is to create an egg myself and keep that egg version-controlled with my buildout. I recreate the egg each time I need to upgrade lxml. You can almost always create a binary egg of any Python project by throwing an import setuptools into the top of its setup.py and then saying python setup.py bdist_egg. And as long as the machines you install the egg on are roughly similar binary-wise (such as all being the same Linux distro), you should not have a terrible lot of trouble. Read up on building lxml with "static deps", as the call them, if you want your egg to not depend on libxml being installed on the box. | 1 | 1 | 0 | We use Hudson-CI for out Continuous Integration server for Python projects, all of which use Buildout to manage dependencies. Almost all our projects use lxml which, because of Buildout, must be built/installed during each test-run and because it takes so long it reduces the number of builds we can run per day.
Is there any way to speed-up the build of lxml when using Buildout? Maybe some environment variables can be set to help the build use both cores on the server? Or something to reduce the amount of optimization done? | How can I speed-up the build/install of lxml? | 0.099668 | 0 | 0 | 962 |
4,314,059 | 2010-11-30T13:04:00.000 | 2 | 0 | 1 | 0 | python,google-app-engine | 4,319,701 | 3 | false | 1 | 0 | This isn't directly possible. You can use multiple equality filters, and the query will only match entities that have at least those items in the list (eg, "WHERE foo = 'a' AND foo = 'b'" will only match if foo is a list containing at least 'a' and 'b'). If you do this without inequality filters or sort orders the datastore will use the built in merge-join strategy to satisfy your query.
Denormalization will provide more robust solutions, however. For example, if you serialize your list as a single string, you can simply check for equality with that string. | 2 | 0 | 0 | If you have a string list in the datastore that has the values:
a,b,c
How can you compare it against a list so that it only returns true if every value in the string list is present in the list?
['a', 'b'] would return false
['a', 'b', 'c'] would return true
['a', 'b', 'c', 'd', 'e'] would return true
Is this possible with GQL alone or would I need to pull put out the string list and loop over it? | App Engine, How to check if all values in a list are in a string list in the datastore | 0.132549 | 0 | 0 | 612 |
4,314,059 | 2010-11-30T13:04:00.000 | 1 | 0 | 1 | 0 | python,google-app-engine | 4,315,502 | 3 | false | 1 | 0 | You can serialize your list in a sorted fashion as a single StringProperty. Depending on the content of your StringListProperty this may be as trivial as comma separated values.
Optionally you can use something like an md5 checksums to reduce the length of the string being stored and filtered against. | 2 | 0 | 0 | If you have a string list in the datastore that has the values:
a,b,c
How can you compare it against a list so that it only returns true if every value in the string list is present in the list?
['a', 'b'] would return false
['a', 'b', 'c'] would return true
['a', 'b', 'c', 'd', 'e'] would return true
Is this possible with GQL alone or would I need to pull put out the string list and loop over it? | App Engine, How to check if all values in a list are in a string list in the datastore | 0.066568 | 0 | 0 | 612 |
4,314,912 | 2010-11-30T14:41:00.000 | 1 | 0 | 1 | 1 | python,multithreading,logging,garbage-collection,multiprocessing | 4,316,259 | 3 | true | 0 | 0 | I agree with @THC4k. This doesn't seem like a GC issue. I'll give you my reasons why, and I'm sure somebody will vote me down if I'm wrong (if so, please leave a comment pointing out my error!).
If you're using CPython, it primarily uses reference counting, and objects are destroyed immediately when the ref count goes to zero (since 2.0, supplemental garbage collection is also provided to handle the case of circular references). Keep a reference to your log object and it won't be destroyed.
If you're using Jython or IronPython, the underlying VM does the garbage collection. Again, keep a reference and the GC shouldn't touch it.
Either way, it seems that either you're not keeping a reference to an object you need to keep alive, or you have some other error. | 2 | 1 | 0 | I create a couple of worker processes using Python's Multiprocessing module 2.6.
In each worker I use the standard logging module (with log rotation and file per worker)
to keep an eye on the worker. I've noticed that after a couple of hours that no more
events are written to the log. The process doesn't appear to crash and still responds
to commands via my queue. Using lsof I can see that the log file is no longer open.
I suspect the log object may be killed by the garbage collector, if so is there a way
that I can mark it to protect it? | How can I protect a logging object from the garbage collector in a multiprocessing process? | 1.2 | 0 | 0 | 534 |
4,314,912 | 2010-11-30T14:41:00.000 | 0 | 0 | 1 | 1 | python,multithreading,logging,garbage-collection,multiprocessing | 4,316,922 | 3 | false | 0 | 0 | You could run gc.collect() immediately after fork() to see if that causes the log to be closed. But it's not likely garbage collection would take effect only after a few hours. | 2 | 1 | 0 | I create a couple of worker processes using Python's Multiprocessing module 2.6.
In each worker I use the standard logging module (with log rotation and file per worker)
to keep an eye on the worker. I've noticed that after a couple of hours that no more
events are written to the log. The process doesn't appear to crash and still responds
to commands via my queue. Using lsof I can see that the log file is no longer open.
I suspect the log object may be killed by the garbage collector, if so is there a way
that I can mark it to protect it? | How can I protect a logging object from the garbage collector in a multiprocessing process? | 0 | 0 | 0 | 534 |
4,315,657 | 2010-11-30T15:54:00.000 | 4 | 0 | 1 | 1 | python,installation | 4,315,780 | 2 | true | 0 | 0 | Configure with:
./configure --prefix=/opt/Python27
In general, you can just do ./configure --help to get a list of all the options you're allowed to set for that configure script. | 2 | 3 | 0 | I want to build Python 2.7.1 additionally to the one the redhat server already has pre-installed.
What options do I need to modify/use so that Python can be built under i.e. /opt/Python27
I would appreciate any help! | How to install Python using source files to a custom directory | 1.2 | 0 | 0 | 2,364 |
4,315,657 | 2010-11-30T15:54:00.000 | 1 | 0 | 1 | 1 | python,installation | 4,319,108 | 2 | false | 0 | 0 | You also want to pass --enable-shared to configure since it is an additional installation of Python. | 2 | 3 | 0 | I want to build Python 2.7.1 additionally to the one the redhat server already has pre-installed.
What options do I need to modify/use so that Python can be built under i.e. /opt/Python27
I would appreciate any help! | How to install Python using source files to a custom directory | 0.099668 | 0 | 0 | 2,364 |
4,319,040 | 2010-11-30T21:49:00.000 | 4 | 0 | 1 | 0 | python,notifications,pynotify | 4,328,158 | 1 | true | 0 | 0 | (Per discussion:)
Setting the append hint on your notifications (set_hint_string('append', '')) tells the notification daemon that it should merge notifications from your app when they have the same titles. | 1 | 2 | 0 | How can I tell a pynotify.Notification object to merge with another that has the same title? | How to merge notifications with a common title in pynotify? | 1.2 | 0 | 0 | 292 |
4,319,392 | 2010-11-30T22:31:00.000 | 0 | 0 | 1 | 0 | python | 4,319,422 | 6 | false | 0 | 0 | The function ord('a') will return the numeric value of 'a' in the current text encoding. You could probably take that and do some simple math to convert to a 1, 2, 3 type mapping. | 1 | 1 | 0 | I need to find the number of an alphabet in the range of alphabets ie a = 1, b=2 , c =3....
So if i get a then the returning value should be 1
Is there a shorter method provided in python(inbuilt) to find it other than declaring a dictionary of 26 alphabets with their respected values.
Please help if you know of such a function..... | Python code for calculating number of an alphabet | 0 | 0 | 0 | 5,642 |
4,320,135 | 2010-12-01T00:25:00.000 | 2 | 0 | 0 | 0 | python,soap,wsdl,jira | 4,350,861 | 1 | true | 1 | 0 | Yes, there's an existing bug on this I've seen. Use the JIRA issue id instead of the key to locate it, as a workaround. | 1 | 3 | 0 | I am trying to do WSDL SOAP connection to our JIRA server using SOAPpy (Python SOAP Library).
All seems to be fine except when I try finding specific issues. Through the web browser looking up the bug ID actually redirects to a bug (with a different ID), however it is the bug in question just moved to a different project.
Attempts to getIssue via the SOAPpy API results in an exception that the issue does not exist.
Any way around this?
Thanks | Python JIRA SOAPpy annoying redirect on findIssue | 1.2 | 0 | 1 | 281 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.