Q_CreationDate
stringlengths
23
23
Title
stringlengths
11
149
Question
stringlengths
25
6.53k
Answer
stringlengths
15
5.1k
Score
float64
-1
1.2
Is_accepted
bool
2 classes
N_answers
int64
1
17
Q_Id
int64
0
6.76k
2009-11-08 10:29:19.143
Does WordNet have "levels"? (NLP)
For example... Chicken is an animal. Burrito is a food. WordNet allows you to do "is-a"...the hiearchy feature. However, how do I know when to stop travelling up the tree? I want a LEVEL. That is consistent. For example, if presented with a bunch of words, I want wordNet to categorize all of them, but at a certain level, so it doesn't go too far up. Categorizing "burrito" as a "thing" is too broad, yet "mexican wrapped food" is too specific. I want to go up the hiearchy or down..until the right LEVEL.
WordNet's hypernym tree ends with a single root synset for the word "entity". If you are using WordNet's C library, then you can get a while recursive structure for a synset's ancestors using traceptrs_ds, and you can get the whole synset tree by recursively following nextss and ptrlst pointers until you hit null pointers.
0
false
4
324
2009-11-08 10:29:19.143
Does WordNet have "levels"? (NLP)
For example... Chicken is an animal. Burrito is a food. WordNet allows you to do "is-a"...the hiearchy feature. However, how do I know when to stop travelling up the tree? I want a LEVEL. That is consistent. For example, if presented with a bunch of words, I want wordNet to categorize all of them, but at a certain level, so it doesn't go too far up. Categorizing "burrito" as a "thing" is too broad, yet "mexican wrapped food" is too specific. I want to go up the hiearchy or down..until the right LEVEL.
[Please credit Pete Kirkham, he first came with the reference to SUMO which may well answer the question asked by Alex, the OP] (I'm just providing a complement of information here; I started in a comment field but soon ran out of space and layout capabilites...) Alex: Most of SUMO is science or engineering? It does not contain every-day words like foods, people, cars, jobs, etc? Pete K: SUMO is an upper ontology. The mid-level ontologies (where you would find concepts between 'thing' and 'beef burrito') listed on the page don't include food, but reflect the sorts of organisations which fund the project. There is a mid-level ontology for people. There's also one for industries (and hence jobs), including food suppliers, but no mention of burritos if you grep it. My two cents 100% of WordNet (3.0 i.e. the latest, as well as older versions) is mapped to SUMO, and that may just be what Alex need. The mid-level ontologies associated with SUMO (or rather with MILO) are effectively in specific domains, and do not, at this time, include Foodstuff, but since WordNet does (include all -well, many of- these everyday things) you do not need to leverage any formal ontology "under" SUMO, but instead use Sumo's WordNet mapping (possibly in addition to WordNet, which, again, is not an ontology but with its informal and loose "hierarchy" may also help. Some difficulty may arise, however, from two area (and then some ;-) ?): the SUMO ontology's "level" may not be the level you'd have in mind for your particular application. For example while "Burrito" brings "Food", at top level entity in SUMO "Chicken" brings well "Chicken" which only through a long chain finds "Animal" (specifically: Chicken->Poultry->Bird->Warm_Blooded_Vertebrae->Vertebrae->Animal). Wordnet's coverage and metadata is impressive, but with regards to the mid-level concepts can be a bit inconsistent. For example "our" Burrito's hypernym is appropriately "Dish", which provides it with circa 140 food dishes, which includes generics such as "Soup" or "Casserole" as well as "Chicken Marengo" (but omitting say "Chicken Cacciatore") My point, in bringing up these issues, is not to criticize WordNet or SUMO and its related ontologies, but rather to illustrate simply some of the challenges associated with building ontology, particularly at the mid-level. Regardless of some possible flaws and lackings of a solution based on SUMO and WordNet, a pragmatic use of these frameworks may well "fit the bill" (85% of the time)
0.454054
false
4
324
2009-11-08 10:29:19.143
Does WordNet have "levels"? (NLP)
For example... Chicken is an animal. Burrito is a food. WordNet allows you to do "is-a"...the hiearchy feature. However, how do I know when to stop travelling up the tree? I want a LEVEL. That is consistent. For example, if presented with a bunch of words, I want wordNet to categorize all of them, but at a certain level, so it doesn't go too far up. Categorizing "burrito" as a "thing" is too broad, yet "mexican wrapped food" is too specific. I want to go up the hiearchy or down..until the right LEVEL.
In order to get levels, you need to predefine the content of each level. An ontology often defines these as the immediate IS_A children of a specific concept, but if that is absent, you need to develop a method of that yourself. The next step is to put a priority on each concept, in case you want to present only one category for each word. The priority can be done in multiple ways, for instance as the count of IS_A relations between the category and the word, or manually selected priorities for each category. For each word, you can then pick the category with the highest priority. For instance, you may want meat to be "food" rather than chemical substance. You may also want to pick some words, that change priority if they are in the path. For instance, if you want some chemicals which are also food, to be announced as chemicals, but others should still be food.
0.16183
false
4
324
2009-11-08 16:24:29.113
Django/SQL: keeping track of who who read what in a forum
I'm working on a not-so-big project in django that will among other things incorporate a forum system. I have most of the system at a more or less functioning state, but I'm still missing a feature to mark unread threads for the users when there are new posts. The thing is I can't really think of a way to properly store that information. My first idea was to create another model that will store a list of threads with changes in them for each user. Something with one ForeignKey(User) and one ForeignKey(Thread) and just keep adding new entries each time a thread is posted or a post is added to a thread. But then, I'm not sure how well that would scale with say several hundred threads after a while and maybe 50-200 users. So add 200 rows for each new post for the users who aren't logged on? Sounds like a lot. How do other forum systems do it anyway? And how can I implement a system to work these things out in Django. Thanks!
You might also simply store the last time a user was reading a particular forum. Any posts that have been updated since that date are new. You'll only be storing one additional piece of information per user as opposed to a piece of information per post per user.
1.2
true
2
325
2009-11-08 16:24:29.113
Django/SQL: keeping track of who who read what in a forum
I'm working on a not-so-big project in django that will among other things incorporate a forum system. I have most of the system at a more or less functioning state, but I'm still missing a feature to mark unread threads for the users when there are new posts. The thing is I can't really think of a way to properly store that information. My first idea was to create another model that will store a list of threads with changes in them for each user. Something with one ForeignKey(User) and one ForeignKey(Thread) and just keep adding new entries each time a thread is posted or a post is added to a thread. But then, I'm not sure how well that would scale with say several hundred threads after a while and maybe 50-200 users. So add 200 rows for each new post for the users who aren't logged on? Sounds like a lot. How do other forum systems do it anyway? And how can I implement a system to work these things out in Django. Thanks!
You're much better off storing the "read" bit, not the "unread" bit. And you can store them not as relational data, but in a giant bit-blob. Then you don't have to modify the read data at all when new posts are added, only when a user reads posts.
0.386912
false
2
325
2009-11-08 17:01:35.417
Which database should I use to store records, and how should I use it?
I'm developing an application that will store a sizeable number of records. These records will be something like (URL, date, title, source, {optional data...}) As this is a client-side app, I don't want to use a database server, I just want the info stored into files. I want the files to be readable from various languages (at least python and C++), so something language specific like python's pickle is out of the game. I am seeing two possibilities: sqlite and BerkeleyDB. As my use case is clearly not relational, I am tempted to go with BerkeleyDB, however I don't really know how I should use it to store my records, as it only stores key/value pairs. Is my reasoning correct? If so, how should I use BDB to store my records? Can you link me to relevant info? Or am I missing a better solution?
Ok, so you say just storing the data..? You really only need a DB for retrieval, lookup, summarising, etc. So, for storing, just use simple text files and append lines. Compress the data if you need to, use delims between fields - just about any language will be able to read such files. If you do want to retrieve, then focus on your retrieval needs, by date, by key, which keys, etc. If you want simple client side, then you need simple client db. SQLite is far easier than BDB, but look at things like Sybase Advantage (very fast and free for local clients but not open-source) or VistaDB or firebird... but all will require local config/setup/maintenance. If you go local XML for a 'sizable' number of records will give you some unnecessarily bloated file-sizes..!
0
false
3
326
2009-11-08 17:01:35.417
Which database should I use to store records, and how should I use it?
I'm developing an application that will store a sizeable number of records. These records will be something like (URL, date, title, source, {optional data...}) As this is a client-side app, I don't want to use a database server, I just want the info stored into files. I want the files to be readable from various languages (at least python and C++), so something language specific like python's pickle is out of the game. I am seeing two possibilities: sqlite and BerkeleyDB. As my use case is clearly not relational, I am tempted to go with BerkeleyDB, however I don't really know how I should use it to store my records, as it only stores key/value pairs. Is my reasoning correct? If so, how should I use BDB to store my records? Can you link me to relevant info? Or am I missing a better solution?
BerkeleyDB is good, also look at the *DBM incarnations (e.g. GDBM). The big question though is: for what do you need to search? Do you need to search by that URL, by a range of URLs or the dates you list? It is also quite possible to keep groups of records as simple files in the local filesystem, grouped by dates or search terms, &c. Answering the "search" question is the biggest start. As for the key/value thingy, what you need to ensure is that the KEY itself is well defined as for your lookups. If for example you need to lookup by dates sometimes and others by title, you will need to maintain a "record" row, and then possibly 2 or more "index" rows making reference to the original record. You can model nearly anything in a key/value store.
0.135221
false
3
326
2009-11-08 17:01:35.417
Which database should I use to store records, and how should I use it?
I'm developing an application that will store a sizeable number of records. These records will be something like (URL, date, title, source, {optional data...}) As this is a client-side app, I don't want to use a database server, I just want the info stored into files. I want the files to be readable from various languages (at least python and C++), so something language specific like python's pickle is out of the game. I am seeing two possibilities: sqlite and BerkeleyDB. As my use case is clearly not relational, I am tempted to go with BerkeleyDB, however I don't really know how I should use it to store my records, as it only stores key/value pairs. Is my reasoning correct? If so, how should I use BDB to store my records? Can you link me to relevant info? Or am I missing a better solution?
Personally I would use sqlite anyway. It has always just worked for me (and for others I work with). When your app grows and you suddenly do want to do something a little more sophisticated, you won't have to rewrite. On the other hand, I've seen various comments on the Python dev list about Berkely DB that suggest it's less than wonderful; you only get dict-style access (what if you want to select certain date ranges or titles instead of URLs); and it's not even in Python 3's standard set of libraries.
0.135221
false
3
326
2009-11-09 11:24:40.500
Environment on google Appengine
does someone have an idea how to get the environment variables on Google-AppEngine ? I'm trying to write a simple Script that shall use the Client-IP (for Authentication) and a parameter (geturl or so) from the URL (for e.g. http://thingy.appspot.dom/index?geturl=www.google.at) I red that i should be able to get the Client-IP via "request.remote_addr" but i seem to lack 'request' even tho i imported webapp from google.appengine.ext Many thanks in advance, Birt
To answer the actual question from the title of your post, assuming you're still wondering: to get environment variables, simple import os and the environment is available in os.environ.
0.386912
false
1
327
2009-11-09 16:11:39.963
How do I profile `paster serve`'s startup time?
Python's paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I would like it to not fork a thread pool and quit as soon as it is ready to serve so the time after it's ready doesn't show up in the profile.
I almost always use paster serve --reload ... during development. That command executes itself as a subprocess (it executes its own script using the subprocess module, not fork()). The subprocess polls for source code changes, quits when it detects a change, and gets restarted by the parent paster serve --reload. That's to say if you're going to profile paster serve itself, omit the --reload argument. Profiling individual requests with middleware should work fine either way. My particular problem was that pkg_resources takes an amount of time proportional to all installed packages when it is first invoked. I solved it by rebuilding my virtualenv without unnecessary packages.
1.2
true
1
328
2009-11-10 09:29:13.153
Client Digest Authentication Python with URLLIB2 will not remember Authorization Header Information
I am trying to use Python to write a client that connects to a custom http server that uses digest authentication. I can connect and pull the first request without problem. Using TCPDUMP (I am on MAC OS X--I am both a MAC and a Python noob) I can see the first request is actually two http requests, as you would expect if you are familiar with RFC2617. The first results in the 401 UNAUTHORIZED. The header information sent back from the server is correctly used to generate headers for a second request with some custom Authorization header values which yields a 200 OK response and the payload. Everything is great. My HTTPDigestAuthHandler opener is working, thanks to urllib2. In the same program I attempt to request a second, different page, from the same server. I expect, per the RFC, that the TCPDUMP will show only one request this time, using almost all the same Authorization Header information (nc should increment). Instead it starts from scratch and first gets the 401 and regenerates the information needed for a 200. Is it possible with urllib2 to have subsequent requests with digest authentication recycle the known Authorization Header values and only do one request? [Re-read that a couple times until it makes sense, I am not sure how to make it any more plain] Google has yielded surprisingly little so I guess not. I looked at the code for urllib2.py and its really messy (comments like: "This isn't a fabulous effort"), so I wouldn't be shocked if this was a bug. I noticed that my Connection Header is Closed, and even if I set it to keepalive, it gets overwritten. That led me to keepalive.py but that didn't work for me either. Pycurl won't work either. I can hand code the entire interaction, but I would like to piggy back on existing libraries where possible. In summary, is it possible with urllib2 and digest authentication to get 2 pages from the same server with only 3 http requests executed (2 for first page, 1 for second). If you happen to have tried this before and already know its not possible please let me know. If you have an alternative I am all ears. Thanks in advance.
Although it's not available out of the box, urllib2 is flexible enough to add it yourself. Subclass HTTPDigestAuthHandler, hack it (retry_http_digest_auth method I think) to remember authentication information and define an http_request(self, request) method to use it for all subsequent requests (add WWW-Authenticate header).
0.386912
false
1
329
2009-11-10 12:57:59.100
Call Python function from MATLAB
I need to call a Python function from MATLAB. how can I do this?
Like Daniel said you can run python commands directly from Matlab using the py. command. To run any of the libraries you just have to make sure Malab is running the python environment where you installed the libraries: On a Mac: Open a new terminal window; type: which python (to find out where the default version of python is installed); Restart Matlab; type: pyversion('/anaconda2/bin/python'), in the command line (obviously replace with your path). You can now run all the libraries in your default python installation. For example: py.sys.version; py.sklearn.cluster.dbscan
0.093914
false
1
330
2009-11-11 06:20:24.523
What if one of my programs runs in python 2.4, but IMPORTS something that requires python 2.5?
Then how do I import that? I run everything in python 2.4, but one of my scripts import xml.etree.ElementTree...which is only Python 2.5
Then it fails. You can't import a python 2.5 library while you're running python 2.4. It won't work. Why can't you run python 2.5+?
1.2
true
1
331
2009-11-12 22:07:34.947
time.sleep and suspend (ie. standby and hibernate)
For example, if I do time.sleep(100) and immediately hibernate my computer for 99 seconds, will the next statement be executed in 1 second or 100 seconds after waking up? If the answer is 1 second, how do you "sleep" 100 seconds, regardless of the length of hibernate/standby?
Clearly, you must sleep according to real, elapsed time. The alternative (sleeping according to some other clock that "somehow" started and stopped) would be unmanageable. How would your application (which is sleeping) be notified of all this starting and stopping activity? Right, it would have to be woken up to be told that it was not supposed to run because the system was hibernating. Or, perhaps, some super-sophisticated OS-level scheduler could be used to determine if some time the system was "busy" vs. "hibernating" counted against the schedules of various sleeping processes. All too complex. Indeed, if you check carefully, sleep is pretty approximate and any Unix Signal will interrupt it. So it's possible to wake early for lots of reasons. Control-C being the big example.
0
false
1
332
2009-11-13 10:13:58.413
How to get process's grandparent id
How can i get process id of the current process's parent? In general given a process id how can I get its parent process id? e.g. os.getpid() can be used to get the proccess id, and os.getppid() for the parent, how do I get grandparent, My target is linux(ubuntu) so platform specific answers are ok.
I do not think you can do this portably in the general case. You need to get this information from the process list (e.g. through the ps command), which is obtained in a system-specific way.
0
false
1
333
2009-11-14 00:30:09.483
Reading Alpha of a PNG Pixel. Fast way via pure Python?
I am having an issue with an embedded 64bit Python instance not liking PIL. Before i start exhausting more methods to get a compiled image editor to read the pixels for me (such as ImageMagick) i am hoping perhaps anyone here can think of a purely Python solution that will be comparable in speeds to the compiled counterparts. Now i am aware that the compiled friends will always be much faster, but i am hoping that because i "just" want to read the alpha of a group of pixels, that perhaps a fast enough pure Python solution can be conjured up. Anyone have any bright ideas? Though, i have tried PyPNG and that is far too slow, so i'm not expecting any magic solutions. None the less, i had to ask. Thanks to any replies! And just for reference, the images i'll be reading will be on average around 512*512 to 2048*2048, and i'll be reading anywhere from one to all of the pixels alpha (multiplied by a few million times, but the values can be stored so reading twice isn't done).
Getting data out of a PNG requires unpacking data and decompressing it. These are likely going to be too slow in Python for your application. One possibility is to start with PyPNG and get rid of anything in it that you don't need. For example, it is probably storing all of the data it reads from the PNG, and some of the slow speed you see may be due to the memory allocations.
1.2
true
1
334
2009-11-14 05:23:14.230
ubuntu9.10 : how to use python's lib-dynload and site-packages directories?
In ubuntu 9.10, in usr/lib/ there are the directories python2.4, python2.5, python2.6 and python3.0 Only python 2.6 is actually working. python2.4 has only a lib-dynload directory, python2.5 has only lib-dynload and site-packages, python3.0 has only a dist-packages directory. Now i'm wondering what is the idea behind this? Because when i install python2.5 with ./configure, make, make install | altinstall this goes into usr/local/lib and not usr/lib/ so why were these directories added tu ubuntu, how am i supposed to install python to use them?
Sounds like they're an accident from some package(s) you have installed. The Python version in use determines the locations searched to find installed Python packages/modules, and the "system version" of Python in Ubuntu 9.10 is 2.6, so that's what practically everything should be using. If you were to install the python2.5 package (or it gets installed as a dependency of something else), then it would use /usr/lib/python2.5/*. Try running which python and python --version; also which python2.6 and which python2.5. From what I understand, though I'm not sure exactly why at all, Debian (from which Ubuntu is derived) uses a dist-packages naming scheme instead of site-packages. Terminology: Python has packages and Debian (and so Ubuntu) has packages. They aren't the same kind of package, though individual Debian packages will install specific Python packages.
0.101688
false
1
335
2009-11-16 00:55:28.293
Compress data before storage on Google App Engine
I im trying to store 30 second user mp3 recordings as Blobs in my app engine data store. However, in order to enable this feature (App Engine has a 1MB limit per upload) and to keep the costs down I would like to compress the file before upload and decompress the file every time it is requested. How would you suggest I accomplish this (It can happen in the background by the way via a task queue but an efficient solution is always good) Based on my own tests and research - I see two possible approaches to accomplish this Zlib For this I need to compress a certain number of blocks at a time using a While loop. However, App Engine doesnt allow you to write to the file system. I thought about using a Temporary File to accomplish this but I havent had luck with this approach when trying to decompress the content from a Temporary File Gzip From reading around the web, it appears that the app engine url fetch function requests content gzipped already and then decompresses it. Is there a way to stop the function from decompressing the content so that I can just put it in the datastore in gzipped format and then decompress it when I need to play it back to a user on demand? Let me know how you would suggest using zlib or gzip or some other solution to accmoplish this. Thanks
You can store up to 10Mb with a list of Blobs. Search for google file service. It's much more versatile than BlobStore in my opinion, since I just started using BlobStore Api yesterday and I'm still figuring out if it is possible to access the data bytewise.. as in changing doc to pdf, jpeg to gif.. You can storage Blobs of 1Mb * 10 = 10 Mb (max entity size I think), or you can use BlobStore API and get the same 10Mb or get 50Mb if you enable billing (you can enable it but if you don't pass the free quota you don't pay).
0
false
2
336
2009-11-16 00:55:28.293
Compress data before storage on Google App Engine
I im trying to store 30 second user mp3 recordings as Blobs in my app engine data store. However, in order to enable this feature (App Engine has a 1MB limit per upload) and to keep the costs down I would like to compress the file before upload and decompress the file every time it is requested. How would you suggest I accomplish this (It can happen in the background by the way via a task queue but an efficient solution is always good) Based on my own tests and research - I see two possible approaches to accomplish this Zlib For this I need to compress a certain number of blocks at a time using a While loop. However, App Engine doesnt allow you to write to the file system. I thought about using a Temporary File to accomplish this but I havent had luck with this approach when trying to decompress the content from a Temporary File Gzip From reading around the web, it appears that the app engine url fetch function requests content gzipped already and then decompresses it. Is there a way to stop the function from decompressing the content so that I can just put it in the datastore in gzipped format and then decompress it when I need to play it back to a user on demand? Let me know how you would suggest using zlib or gzip or some other solution to accmoplish this. Thanks
"Compressing before upload" implies doing it in the user's browser -- but no text in your question addresses that! It seems to be about compression in your GAE app, where of course the data will only be after the upload. You could do it with a Firefox extension (or other browsers' equivalents), if you can develop those and convince your users to install them, but that has nothing much to do with GAE!-) Not to mention that, as @RageZ's comment mentions, MP3 is, essentially, already compressed, so there's little or nothing to gain (though maybe you could, again with a browser extension for the user, reduce the MP3's bit rate and thus the file's dimension, that could impact the audio quality, depending on your intended use for those audio files). So, overall, I have to second @jldupont's suggestion (also in a comment) -- use a different server for storage of large files (S3, Amazon's offering, is surely a possibility though not the only one).
1.2
true
2
336
2009-11-16 09:23:41.317
How to make PowerBuilder UI testing application?
I'm not familiar with PowerBuilder but I have a task to create Automatic UI Test Application for PB. We've decided to do it in Python with pywinauto and iaccesible libraries. The problem is that some UI elements like newly added lists record can not be accesed from it (even inspect32 can't get it). Any ideas how to reach this elements and make them testable?
I'm experimenting with code for a tool for automating PowerBuilder-based GUIs as well. From what I can see, your best bet would be to use the PowerBuilder Native Interface (PBNI), and call PowerScript code from within your NVO. If you like, feel free to send me an email (see my profile for my email address), I'd be interested in exchanging ideas about how to do this.
0.201295
false
2
337
2009-11-16 09:23:41.317
How to make PowerBuilder UI testing application?
I'm not familiar with PowerBuilder but I have a task to create Automatic UI Test Application for PB. We've decided to do it in Python with pywinauto and iaccesible libraries. The problem is that some UI elements like newly added lists record can not be accesed from it (even inspect32 can't get it). Any ideas how to reach this elements and make them testable?
I've seen in AutomatedQa support that they a recipe recommending using msaa and setting some properties on the controls. I do not know if it works.
0.101688
false
2
337
2009-11-17 12:19:04.847
Python: Connect blender with WinTracker 2
I am trying to develop a project that uses a control model in Blender by using WinTracker machine, but I don't know how to connect it with Blender Game Engine. How can I connect it with Blender Game Engine?
You must write the plug-in for blender and used the wintracker driver. It is ready for c Lagrange. but you have "wintracker2"? I wanted to buy it but the company said "it's not ready to seal".
0
false
1
338
2009-11-17 18:01:16.637
Django development server CPU intensive - how to analyse?
I'm noticing that my django development server (version 1.1.1) on my local windows7 machine is using a lot of CPU (~30%, according to task manager's python.exe entry), even in idle state, i.e. no request coming in/going out. Is there an established way of analysing what might be responsible for this? Thanks! Martin
FWIW, you should do the profiling, but when you do I'll bet you find that the answer is "polling for changes to your files so it can auto-reload." You might do a quick test with "python manage.py runserver --noreload" and see how that affects the CPU usage.
1.2
true
2
339
2009-11-17 18:01:16.637
Django development server CPU intensive - how to analyse?
I'm noticing that my django development server (version 1.1.1) on my local windows7 machine is using a lot of CPU (~30%, according to task manager's python.exe entry), even in idle state, i.e. no request coming in/going out. Is there an established way of analysing what might be responsible for this? Thanks! Martin
Hit Control-C and crash the process. It will probably crash somewhere that it's spending a lot of time. Or you could use a profiler.
0.386912
false
2
339
2009-11-20 17:41:19.937
pysvn with svn+ssh
I'm working with pysvn, and I'm trying to find a decent way to handle repositories that are only accessible via svn+ssh. Obviously SSH keys make this all incredibly easy, but I can't guarantee the end user will be using an SSH key. This also has to be able to run without user interaction, because it's going to be doing some svn log parsing. The big issue is that, with svn+ssh an interactive prompt is popped up for authentication. Obviously I'd like to be able to have pysvn automatically login with a set of given credentials, but set_default_username and set_default_password aren't doing me any good in that respect. If I can't have that, I'd at least like to able to just fail out, and log a message to tell the user to setup an SSH key. However, set_interactive seems to have no bearing on this either, and I'm still prompted for a password with client.log('svn+ssh://path'). Any thoughts on how to tackle this issue? Is it even really possible to handle this without SSH keys, since it's SSH that's throwing the prompts?
Check out ssh configuration option PasswordAuthentication. I'm not sure how pysvn interacts with ssh, but if you set this to no in your ~/.ssh/config (or maybe global config?) then it shouldn't prompt for a password.
1.2
true
1
340
2009-11-20 21:02:50.160
Linking Tcl/Tk to Python 2.5
I have an existing Python 2.4 and it is working properly with tkinter as I tested it using python import _tkinter import Tkinter Tkinter._test() Now, I have installed python 2.5.2 but when I try the same tests (with the newer version), it returns (but the same tests are working for the previous version) ImportError: No module named _tkinter I know that tcl8.5 and tk8.5 are installed on my machine as the following commands return there locations whereis tcl tcl: /usr/lib/tcl8.4 /usr/local/lib/tcl8.5 /usr/local/lib/tcl8.4 /usr/share/tcl8.4 whereis tk tk: /usr/lib/tk8.4 /usr/local/lib/tk8.5 /usr/share/tk8.4 Any ideas how do I make my newer python version work with tkinter?
The files you found are for linking directly to tcl/tk. Python depends on another library as well: _tkinter.so. It should be in /usr/lib/python2.5/lib-dynload/_tkinter.so. How did you install python2.5? If you are using Debian or Ubuntu you need to install the python-tk package to get Tkinter support. If the _tkinter.so file is there, your environment could be causing problems. If python -E -c "import Tkinter;Tkinter._test()" suceeds, but python -c "import Tkinter;Tkinter._test()" fails, then the problem is with how your environment is set up. Check the value of PYTHONPATH is set correctly.
0.995055
false
1
341
2009-11-21 18:24:26.190
replacing Matlab with python
i am a engineering student and i have to do a lot of numerical processing, plots, simulations etc. The tool that i use currently is Matlab. I use it in my university computers for most of my assignments. However, i want to know what are the free options available. i have done some research and many have said that python is a worthy replacement for matlab in various scenarios. i want to know how to do all this with python. i am using a mac so how do i install the different python packages. what are those packages? is it really a viable alternative? what are the things i can and cannot do using this python setup?
I've been programming with Matlab for about 15 years, and with Python for about 10. It usually breaks down this way: If you can satisfy the following conditions: 1. You primarily use matrices and matrix operations 2. You have the money for a Matlab license 3. You work on a platform that mathworks supports Then, by all means, use Matlab. Otherwise, if you have data structures other than matrices, want an open-source option that allows you to deliver solutions without worrying about licenses, and need to build on platforms that mathworks does not support; then, go with Python. The matlab language is clunky, but the user interface is slick. The Python language is very nice -- with iterators, generators, and functional programming tools that matlab lacks; however, you will have to pick and choose to put together a nice slick interface if you don't like (or can't use) SAGE. I hope that helps.
0.580532
false
1
342
2009-11-22 18:10:35.207
Django: request.META['REMOTE_ADDR'] is always '127.0.0.1'
I have an application running with debug=True on a remote host somewhere. Now somehow every time I access REMOTE_ADDR it returns 127.0.0.1 no matter where the request is from. I'm not sure where to start and why this is happening.
Do you have any kind of proxy, gateway, or load balancer running on that remote host? That's the sort of thing that would cause connections to appear to be from 127.0.0.1 (because that's where the immediate connection is from, as far as the web server is concerned).
1.2
true
1
343
2009-11-23 06:28:45.727
Python for web scripting
I'm just starting out with Python and have practiced so far in the IDLE interface. Now I'd like to configure Python with MAMP so I can start creating really basic webapps — using Python inside HTML, or well, vice-versa. (I'm assuming HTML is allowed in Python, just like PHP? If not, are there any modules/template engines for that?) What modules do I need to install to run .py from my localhost? Googling a bit, it seems there're various methods — mod_python, FastCGI etc.. which one should I use and how to install it with MAMP Pro 1.8.2? Many thanks
You asked whether HTML is allowed within Python, which indicates that you still think too much in PHP terms about it. Contrary to PHP, Python was not designed to create dynamic web-pages. Instead, it was designed as a stand-alone, general-purpose programming language. Therefore you will not be able to put HTML into Python. There are some templating libraries which allow you to go the other way around, somewhat, but that's a completely different issue. With things like Django or TurboGears or all the other web-frameworks, you essentially set up a small, stand-alone web-server (which comes bundled with the framework so you don't have to do anything), tell the server which function should handle what URL and then write those functions. In the simplest case, each URL you specify has its own function. That 'handler function' (or 'view function' in Django terminology) receives a request object in which interesting info about the just-received request is contained. It then does whatever processing is required (a DB query for example). Finally, it produces some output, which is returned to the client. A typical way to get the output is to have some data passed to a template where it is rendered together with some HTML. So, the HTML is separated in a template (in the typical case) and is not in the Python code. About Python 3: I think you will find that the vast majority of all Python development going on in the world is still with Python 2.*. As others have pointed out here, Python 3 is just coming out, most of the good stuff is not available for it yet, and you shouldn't be bothered about that. My advise: Grab yourself Python 2.6 and Django 1.1 and dive in. It's fun.
0.265586
false
1
344
2009-11-25 07:59:24.200
converting basic HTML to RML (Reportlab Markup Language)
Is there any Python library or some sample code which demonstrates how to convert basic HTML into RML (Reportlab Markup Language www.reportlab.org)? I can think of using a regular HTML parser and adding some home grown code to generate the RML, but I guess there will be a lot of cases to handle in such a conversion.
You shouldn't have much trouble doing this. Aside from some differences in element names, it's pretty straightforward: just ignore any HTML elements that can't be easily converted/you don't care about converting to RML and do the rest. I'm sure the ReportLab folks would be glad if you contributed even a basic HTML to RML parser to the project.
1.2
true
1
345
2009-11-26 13:43:32.063
Error codes returned by urllib/urllib2 and the actual page
the normal behavior of urllib/urllib2 is if an error code is sent in the header of the response (i.e 404) an Exception is raised. How do you look for specific errors i.e (40x, or 50x) based on the different errors, do different things. Also, how do you read the actual data being returned HTML/JSON etc (The data usually has error details which is different to the HTML error code)
In urllib2 HTTPError exception is also a valid HTTP response, so you can treat an HTTP error as an exceptional event or valid response. But in urllib you have to subclass URLopener and define http_error_<code> method[s] or redefine http_error_default to handle them all.
0.201295
false
1
346
2009-11-28 01:24:12.507
How can I run redemo.py (or equivalent) on a Mac?
In the Python installation on my PC there is a sweet script in C:\python26\tools\scripts called redemo.py. It's a simple tk application for testing regular expressions. I wish I could get it--or something like it--running on my Mac, but I don't know how. The script doesn't appear to be part of the Python installation on my Mac. Ideas?
Install Python on your Mac, then copy the script over? It should work fine on any Python installation.
0
false
1
347
2009-11-28 08:04:14.477
I want to develop a framework in Python for desktop based applications. How should I go about it?
I want to develop a desktop application framework in Python, much like QT, but how to go about it? Any tutorials or links related to it would be helpful!
Well the best way to start is to look at the source code of the framework the other answers are talking about. First, try to use them all to build the same application with the functionalities you expect from a framework. Them, look at how it works under the hood. Secondly, build your framework, starting by writing your first widgets, then notice the problems with your current architecture, and re factor. Start again, until you have something stable and usable. Eventually, find out this was nice as training experience, but useless as a contribution to the software communities since you will never reach out the qualities of existing tools. Then give up and try to code your own MMORPG.
1.2
true
1
348
2009-11-28 09:46:38.660
How to safely write to a file?
Imagine you have a library for working with some sort of XML file or configuration file. The library reads the whole file into memory and provides methods for editing the content. When you are done manipulating the content you can call a write to save the content back to file. The question is how to do this in a safe way. Overwriting the existing file (starting to write to the original file) is obviously not safe. If the write method fails before it is done you end up with a half written file and you have lost data. A better option would be to write to a temporary file somewhere, and when the write method has finished, you copy the temporary file to the original file. Now, if the copy somehow fails, you still have correctly saved data in the temporary file. And if the copy succeeds, you can remove the temporary file. On POSIX systems I guess you can use the rename system call which is an atomic operation. But how would you do this best on a Windows system? In particular, how do you handle this best using Python? Also, is there another scheme for safely writing to files?
If you see Python's documentation, it clearly mentions that os.rename() is an atomic operation. So in your case, writing data to a temporary file and then renaming it to the original file would be quite safe. Another way could work like this: let original file be abc.xml create abc.xml.tmp and write new data to it rename abc.xml to abc.xml.bak rename abc.xml.tmp to abc.xml after new abc.xml is properly put in place, remove abc.xml.bak As you can see that you have the abc.xml.bak with you which you can use to restore if there are any issues related with the tmp file and of copying it back.
1.2
true
2
349
2009-11-28 09:46:38.660
How to safely write to a file?
Imagine you have a library for working with some sort of XML file or configuration file. The library reads the whole file into memory and provides methods for editing the content. When you are done manipulating the content you can call a write to save the content back to file. The question is how to do this in a safe way. Overwriting the existing file (starting to write to the original file) is obviously not safe. If the write method fails before it is done you end up with a half written file and you have lost data. A better option would be to write to a temporary file somewhere, and when the write method has finished, you copy the temporary file to the original file. Now, if the copy somehow fails, you still have correctly saved data in the temporary file. And if the copy succeeds, you can remove the temporary file. On POSIX systems I guess you can use the rename system call which is an atomic operation. But how would you do this best on a Windows system? In particular, how do you handle this best using Python? Also, is there another scheme for safely writing to files?
The standard solution is this. Write a new file with a similar name. X.ext# for example. When that file has been closed (and perhaps even read and checksummed), then you two two renames. X.ext (the original) to X.ext~ X.ext# (the new one) to X.ext (Only for the crazy paranoids) call the OS sync function to force dirty buffer writes. At no time is anything lost or corruptable. The only glitch can happen during the renames. But you haven't lost anything or corrupted anything. The original is recoverable right up until the final rename.
0.201295
false
2
349
2009-11-29 02:20:09.160
Allow only one concurrent login per user in django app
is it possible to allow only one concurrent login per user in django application? if yes, how do you approach?
I'm going to assume that you mean logged in at once, and not one "login" at the same time. I've never written a Django application before. But one method I've used in other languages, is to store the session ID of the logged in user in their user row in the database. For example, if you have a users table in your database, add a field "session_id" and then when the user logs in, set that to their current session_id. On every page load check to see if their current session matches the session_id in the users table. Remember whenever you regenerate their session_id in your application, you'll need to update the database so they don't get logged out. Some people when a user logs in, just store all the users details into a session and never re-call the database on a new page load. So for some this "extra" SQL query might seem wrong. For me, I always do a new query on each page load to re-authenticate the user and make sure their account wasn't removed/suspended and to make sure their username/password combo is still the same. (What if someone from another location changed the password, or an administrator?)
0
false
1
350
2009-11-30 10:20:03.557
Close and open a new browser in Selenium
I'm writing a script which needs the browser that selenium is operating close and re-open, without losing its cookies. Any idea on how to go about it? Basically, it's a check to see that if the user opens and closes his browser, his cookies stay intact.
You should be able to use the stop and start commands. You will need to ensure that you are not clearing cookies between sessions, and depending on the browser you're launching you may also need to use the -browserSessionReuse command line option.
0.545705
false
2
351
2009-11-30 10:20:03.557
Close and open a new browser in Selenium
I'm writing a script which needs the browser that selenium is operating close and re-open, without losing its cookies. Any idea on how to go about it? Basically, it's a check to see that if the user opens and closes his browser, his cookies stay intact.
This is a feature of the browser and not your concern: If there is a bug in the browser, then there is little you can do. If you need to know whether a certain version of the browser works correctly, then define a manual test (write a document that explains the steps), do it once and record the result somewhere (like "Browser XXX version YYY works"). When you know that a certain browser (version) works, then that's not going to change, so there is no need to repeat the test.
0
false
2
351
2009-11-30 13:42:54.487
Javascript communication with Selenium (RC)
My Application has a lot of calculation being done in JavaScript according to how and when the user acts on the application. The project prints out valuable information (through console calls) as to how this calculation is going on, and so we can easily spot any NaNs creeping in. We are planning to integrate Selenium (RC with python) to test or project, but if we could get the console output messages in the python test case, we can identify any NaNs or even any miscalculations. So, is there a way that Selenium can absorb these outputs (preferably in a console-less environment)? If not, I would like to know if I can divert the console calls, may be by rebinding the console variable to something else, so that selenium can get that output and notify the python side. Or if not console, is there any other way that I can achieve this. I know selenium has commands like waitForElementPresent etc., but I don't want to show these intermediate calculations on the application, or is it the only way? Any help appreciated. Thank you.
If you are purely testing that the JavaScript functions are performing the correct calculations with the given inputs, I would suggest separating your JavaScript from your page and use a JavaScript testing framework to test the functionality. Testing low level code using Selenium is a lot of unnecessary overhead. If you're going against the fully rendered page, this would require your application to be running to a server, which should not be a dependency of testing raw JavaScript. We recently converted our application from using jsUnit to use YUI Test and it has been promising so far. We run about 150 tests in both FireFox and IE in less than three minutes. Our testing still isn't ideal - we still test a lot of JavaScript the hard way using Selenium. However, moving some of the UI tests to YUI Test has saved us a lot of time in our Continuous Integration environment.
0.201295
false
1
352
2009-12-01 18:38:46.943
Python syntax highlighting / Intellisense?
I've started messing around with Google App Engine, writing Python. I love Visual Studio for many reasons, but currently my .py files just look like text. I've searched the web looking for a way to get it to highlight python files (intellisense would be a nice bonus, but not required) but turned up nothing. There are other questions on SO about this, but all the answers point at different IDEs, or installing IronPythonStudio (which seems overkill since I only want to colouring, and it might behave differently being geared at .NET anyway). Does anyone know how to simple get VS to highlight Python? Is it really that uncommon? :(
Thanks for all the responses. I did scan through some Python IDEs (and their screenshots) and decided to check out IronPythonStudio. My .py files now get colour coded nicely, and there's some intellisense :) Unfortunately Ctrl+K,D doesn't work, but it's much nicer to code than the plain yellow text I had earlier. For anyone that's a massive Visual Studio fanboy like me, IronPythonStudio is definitely better than just coding it as text ;o)
1.2
true
1
353
2009-12-03 04:43:05.963
Compressing UTF-8(or other 8-bit encoding) to 7 or fewer bits
I wish to take a file encoded in UTF-8 that doesn't use more than 128 different characters, then move it to a 7-bit encoding to save the 1/8 of space. For example, if I have a 16 MB text file that only uses the first 128(ascii) characters, I would like to shave off the extra bit to reduce the file to 14MB. How would I go about doing this? There doesn't seem to be an existing free or proprietary program to do so, so I was thinking I might try and make a simple(if inefficient) one. The basic idea I have is to make a function from the current hex/decimal/binary values used for each character to the 128 values I would have in the seven bit encoding, then scan through the file and write each modified value to a new file. So if the file looked like(I'll use a decimal example because I try not to have to think in hex) 127 254 025 212 015 015 132... It would become 001 002 003 004 005 005 006 If 127 mapped to 001, 254 mapped to 005, etc. I'm not entirely sure on a couple things, though. Would this be enough to actually shorten the filesize? I have a bad feeling this would simply leave an extra 0 on the binary string--11011001 might get mapped to 01000001 rather than 1000001, and I won't actually save space. If this would happen, how do I get rid of the zero? How do I open the file to read/write in binary/decimal/hex rather than just text? I've mostly worked with Python, but I can muddle through C if I must. Thank you.
"this would simply leave an extra 0 on the binary string--11011001 might get mapped to 01000001 rather than 1000001, and I won't actually save space." Correct. Your plan will do nothing.
0
false
3
354
2009-12-03 04:43:05.963
Compressing UTF-8(or other 8-bit encoding) to 7 or fewer bits
I wish to take a file encoded in UTF-8 that doesn't use more than 128 different characters, then move it to a 7-bit encoding to save the 1/8 of space. For example, if I have a 16 MB text file that only uses the first 128(ascii) characters, I would like to shave off the extra bit to reduce the file to 14MB. How would I go about doing this? There doesn't seem to be an existing free or proprietary program to do so, so I was thinking I might try and make a simple(if inefficient) one. The basic idea I have is to make a function from the current hex/decimal/binary values used for each character to the 128 values I would have in the seven bit encoding, then scan through the file and write each modified value to a new file. So if the file looked like(I'll use a decimal example because I try not to have to think in hex) 127 254 025 212 015 015 132... It would become 001 002 003 004 005 005 006 If 127 mapped to 001, 254 mapped to 005, etc. I'm not entirely sure on a couple things, though. Would this be enough to actually shorten the filesize? I have a bad feeling this would simply leave an extra 0 on the binary string--11011001 might get mapped to 01000001 rather than 1000001, and I won't actually save space. If this would happen, how do I get rid of the zero? How do I open the file to read/write in binary/decimal/hex rather than just text? I've mostly worked with Python, but I can muddle through C if I must. Thank you.
What you need is UTF-7. Edit: UTF-7 has the advantage of bloating "only" special characters, so if special characters are rare in the input, you get far less bytes than by just converting UTF-8 to 7 bit. That's what UTF-7 is for.
-0.135221
false
3
354
2009-12-03 04:43:05.963
Compressing UTF-8(or other 8-bit encoding) to 7 or fewer bits
I wish to take a file encoded in UTF-8 that doesn't use more than 128 different characters, then move it to a 7-bit encoding to save the 1/8 of space. For example, if I have a 16 MB text file that only uses the first 128(ascii) characters, I would like to shave off the extra bit to reduce the file to 14MB. How would I go about doing this? There doesn't seem to be an existing free or proprietary program to do so, so I was thinking I might try and make a simple(if inefficient) one. The basic idea I have is to make a function from the current hex/decimal/binary values used for each character to the 128 values I would have in the seven bit encoding, then scan through the file and write each modified value to a new file. So if the file looked like(I'll use a decimal example because I try not to have to think in hex) 127 254 025 212 015 015 132... It would become 001 002 003 004 005 005 006 If 127 mapped to 001, 254 mapped to 005, etc. I'm not entirely sure on a couple things, though. Would this be enough to actually shorten the filesize? I have a bad feeling this would simply leave an extra 0 on the binary string--11011001 might get mapped to 01000001 rather than 1000001, and I won't actually save space. If this would happen, how do I get rid of the zero? How do I open the file to read/write in binary/decimal/hex rather than just text? I've mostly worked with Python, but I can muddle through C if I must. Thank you.
Just use gzip compression, and save 60-70% with 0% effort!
0.995055
false
3
354
2009-12-03 21:57:03.280
how to transition from C# to python?
i feel like i'm going back to the stone age. how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?
A mistake people coming from C# or Java make a lot is recreate a large class hierarchy like is common in those languages. With Python this is almost never useful. Instead, learn about duck typing. And don't worry too much about the lack of static typing: in practice, it's almost never an issue.
0.025505
false
10
355
2009-12-03 21:57:03.280
how to transition from C# to python?
i feel like i'm going back to the stone age. how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?
I suggest going cold turkey - languages like Python shine with great text editors. Choose one you want to become amazing at (vim, emacs, etc.) and never look back.
0
false
10
355
2009-12-03 21:57:03.280
how to transition from C# to python?
i feel like i'm going back to the stone age. how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?
Same way you do anything else that doesn't have IntelliStuff. I'm betting you wrote that question without the aid of an IntelliEnglish computer program that showed you a list of verbs you could use and automatically added punctuation at the end of your sentences, for example. :-)
0.025505
false
10
355
2009-12-03 21:57:03.280
how to transition from C# to python?
i feel like i'm going back to the stone age. how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?
<rant> This is sort of the reason that I think being a good visual studio user makes you a bad developer. Instead of learning an API, you look in the object browser until you find something that sounds more or less like what you are looking for, instantiate it, then hit . and start looking for what sounds like the right thing to use. While this is very quick, it also means it takes forever to learn an API in any depth, which often means you end up either re-inventing the wheel (because the wheel is buried under a mountain worth of household appliances and you had no idea it was there), or just doing things in a sub-optimal way. Just because you can find A solution quickly, doesn't mean it is THE BEST solution. </rant> In the case of .NET, which ships with about a billion APIs for everything under the sun, this is actually preferred. You need to sift through a lot of noise to find what you are aiming for. Pythonic code favors one, obvious way to do any given thing. This tends to make the APIs very straight forward and readable. The trick is to learn the language and learn the APIs. It is not terribly hard to do, especially in the case of python, and while not being able to rely on intellisense may be jarring at first, it shouldn't take more then a week or two before you get used to it not being there. Learn the language and the basic standard libraries with a good book. When it comes to a new library API, I find the REPL and some exploratory coding can get me to a pretty good understanding of what is going on fairly quickly.
0.101688
false
10
355
2009-12-03 21:57:03.280
how to transition from C# to python?
i feel like i'm going back to the stone age. how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?
Don't worry about intellisense. Python is really simple and there really isn't that much to know, so after a few projects you'll be conceiving of python code while driving, eating, etc., without really even trying. Plus, python's built in text editor (IDLE) has a wimpy version of intellisense that has always been more than sufficient for my purposes. If you ever go blank and want to know what methods/properties and object has, just type this in an interactive session: dir(myobject)
0.025505
false
10
355
2009-12-03 21:57:03.280
how to transition from C# to python?
i feel like i'm going back to the stone age. how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?
You could always start with IronPython and continue to develop in Visual Studio.
0.050976
false
10
355
2009-12-03 21:57:03.280
how to transition from C# to python?
i feel like i'm going back to the stone age. how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?
I'm not too familiar with Python so I'll give some general advice. Make sure to print out some reference pages of common functions. Keep them by you(or pinned to a wall or desk) at all times when your programming.. I'm traditionally a "stone age" developer and after developing in VS for a few months I'm finding my hobby programming is difficult without intellisense.. but keep at it to memorize the most common functions and eventually it'll just be natural You'll also have to get use to a bit more "difficult" of debugging(not sure how that works with python) While your learning though, you should enjoy the goodness(at least compared to C#) of Python even if you don't have intellisense.. hopefully this will motivate you!
0
false
10
355
2009-12-03 21:57:03.280
how to transition from C# to python?
i feel like i'm going back to the stone age. how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?
The python ide from wingware is pretty nice. Thats what I ended up using going from visual studio C++/.net to doing python.
0.050976
false
10
355
2009-12-03 21:57:03.280
how to transition from C# to python?
i feel like i'm going back to the stone age. how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?
I've only ever used IDLE for python development and it is not fun in the least. I would recommend getting your favorite text editor, mine is notepad++, and praying for a decent plugin for it. I only ever had to go from Eclipse to Visual Studio so my opinions are generally invalid in these contexts.
0
false
10
355
2009-12-03 21:57:03.280
how to transition from C# to python?
i feel like i'm going back to the stone age. how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?
One step at a time? Start off with simple programs (things you can write with your eyes closed in C#), and keep going... You will end up knowing the API by heart.
0.126864
false
10
355
2009-12-04 14:02:47.403
Best XMPP Library for Python Web Application
I want to learn how to use XMPP and to create a simple web application with real collaboration features. I am writing the application with Python(WSGI), and the application will require javascript enabled because I am going to use jQuery or Dojo. I have downloaded Openfire for the server and which lib to choose? SleekXMPP making trouble with tlslite module(python 2.5 and I need only python 2.6). What is your suggestion?
I have found a lot of issues with Openfire and TLS are not with the xmpp lib :( -- SleekXMPP in the trunk has been converted to Python 3.0 and the branch is maintained for Python 2.5 Unlike Julien, I would only go with Twisted Words if you really need the power of Twisted or if you are already using Twisted. IMO SleekXMPP offers the closest match to the current XEP's in use today.
0
false
1
356
2009-12-07 10:38:17.450
problem with pyglet playing video
I'm new to pyglet and i have a problem with video.. I'm trying to play a video using pyglet .. but instead of playing the video in the window it just exits immediately and terminates .. do you guys have any solution for this problem how can i hold the window to play vedio?? i use windows vista 64x with python 2.5 please help and here is the code : vidPath="vid.avi" widnow = pyglet.window.Window() source = pyglet.media.StreamingSource() MediaLoad = pyglet.media.load(vidPath) player = pyglet.media.Player() player.queue(MediaLoad) player.play() @window.event ...def on_draw(): ... player.get_texture.blit(0,0) thank u very much for your time
I think calling "pyglet.app.run()" is missing.
1.2
true
1
357
2009-12-07 16:52:25.453
Writing my own django-cms plugin. Any recommendations?
I don't see any possibility for creating a table in django-cms. I need this functionnality so I am evaluating the possibility to write my own plugin. I am getting started with this product. I've read the documentation carefully and I see more or less how to do that. However, I would be happy to hear some tips and tricks before starting this task. Does anybody have experience with django-cms plugin? Thanks in advance
This all depends on your model. Plugins use standard django admin features. This also depends on the source data for the table. If you have a CSV or Exel sheet as source i only would make a file field and render the file in the render function with some optional caching. If you want to enter data by hand: A Table model. An Row model with a foreign key to table. The row model can then be used as a django-admin Inline. So you can add new rows as needed. Be aware that CMSPluginBase extends ModelAdmin so you can define inlines like you would do in normal admin.
1.2
true
1
358
2009-12-08 21:59:17.270
Render in infinity loop
Question for Python 2.6 I would like to create an simple web application which in specified time interval will run a script that modifies the data (in database). My problem is code for infinity loop or some other method to achieve this goal. The script should be run only once by the user. Next iterations should run automatically, even when the user leaves the application. If someone have idea for method detecting apps breaks it would be great to show it too. I think that threads can be the best way to achive that. Unfortunately, I just started my adventure with Python and don't know yet how to use them. The application will have also views showing database and for control of loop script. Any ideas?
Can you use cron to schedule the job to run at certain intervals? It's usually considered better than infinite loops, and was designed to help solve this sort of problem.
0
false
1
359
2009-12-10 09:42:32.627
DJANGO : Update div with AJAX
I am building a chat application. So far I am adding chat messages with jquery $.post() and this works fine. Now I need to retrieve the latest chat message from the table and append the list on the chat page. I am new to Django, so please go slow. So how do I get data from the chat table back to the chat page? Thanks in advance!
Since you're already using an AJAX post, why don't you return the data from that and insert it into the div? The view that accepts the post can return a rendered template or JSON, and your javascript can insert it in the callback.
0.265586
false
1
360
2009-12-10 15:41:09.420
How to unpickle from C code
I have a python code computing a matrix, and I would like to use this matrix (or array, or list) from C code. I wanted to pickle the matrix from the python code, and unpickle it from c code, but I could not find documentation or example on how to do this. I found something about marshalling data, but nothing about unpickling from C. Edit : Commenters Peter H asked if I was working with numpy arrays. The answer is yes.
take a look at module struct ?
0
false
1
361
2009-12-13 14:46:44.253
How to return a float point number with a defined number of decimal places?
So I know how to print a floating point number with a certain decimal places. My question is how to return it with a specified number of decimal places? Thanks.
In order to get two decimal places, multiply the number by 100, floor it, then divide by 100. And note that the number you will return will not really have only two decimal places because division by 100 cannot be represented exactly in IEEE-754 floating-point arithmetic most of the time. It will only be the closest representable approximation to a number with only two decimal places.
0.386912
false
2
362
2009-12-13 14:46:44.253
How to return a float point number with a defined number of decimal places?
So I know how to print a floating point number with a certain decimal places. My question is how to return it with a specified number of decimal places? Thanks.
Floating point numbers have infinite number of decimal places. The physical representation on the computer is dependent on the representation of float, or double, or whatever and is dependent on a) language b) construct, e.g. float, double, etc. c) compiler implementation d) hardware. Now, given that you have a representation of a floating point number (i.e. a real) within a particular language, is your question how to round it off or truncate it to a specific number of digits? There is no need to do this within the return call, since you can always truncate/round afterwards. In fact, you would usually not want to truncate until actually printing, to preserve more precision. An exception might be if you wanted to ensure that results were consistent across different algorithms/hardware, ie. say you had some financial trading software that needed to pass unit tests across different languages/platforms etc.
0.201295
false
2
362
2009-12-13 21:07:43.213
Executing server-side Unix scripts asynchronously
We have a collection of Unix scripts (and/or Python modules) that each perform a long running task. I would like to provide a web interface for them that does the following: Asks for relevant data to pass into scripts. Allows for starting/stopping/killing them. Allows for monitoring the progress and/or other information provided by the scripts. Possibly some kind of logging (although the scripts already do logging). I do know how to write a server that does this (e.g. by using Python's built-in HTTP server/JSON), but doing this properly is non-trivial and I do not want to reinvent the wheel. Are there any existing solutions that allow for maintaining asynchronous server-side tasks?
Django is great for writing web applications, and the subprocess module (subprocess.Popen en .communicate()) is great for executing shell scripts. You can give it a stdin,stdout and stderr stream for communication if you want.
0.135221
false
1
363
2009-12-14 17:38:08.390
How to implement time event scheduler in python?
In python how to implement a thread which runs in the background (may be when the module loads) and calls the function every minute Monday to Friday 10 AM to 3 PM. For example the function should be called at: 10:01 AM 10:02 AM 10:03 AM . . 2:59 PM Any pointers? Environment: Django Thanks
Django is a server application, which only reacts to external events. You should use a scheduler like cron to create events that call your django application, either calling a management subcommand or doing an HTTP request on some special page.
1.2
true
1
364
2009-12-15 14:21:15.453
Integrate Python app into PHP site
This might sound really crazy, but still... For our revamped project site, we want to integrate Trac (as code browser, developer wiki and issue tracker) into the site design. That is, of course, difficult, since Trac is written in Python and our site in PHP. Does anybody here know a way how to integrate a header and footer (PHP) into the Trac template (preferrably without invoking a - or rather two for header and footer - PHP process from the command line)?
The best option probably is to (re)write the header and footer using python. If the header and footer are relatively static you can also generate them once using php (or once every x minutes) and include them from the filesystem. (You probably already thought about this and dismissed the idea because your sites are too dynamic to use this option?) While I would not really recommend it you could also use some form of AJAX to load parts of the page, and nothing prevents you from loading this content from a php based system. That could keep all parts dynamic. Your pages will probably look ugly while loading, and you now generate more hits on the server than needed, but if it is nog a big site this might be a big. Warning: If you have user logins on both systems you will probably run into problems with people only being logged in to half of your site.
0.135221
false
2
365
2009-12-15 14:21:15.453
Integrate Python app into PHP site
This might sound really crazy, but still... For our revamped project site, we want to integrate Trac (as code browser, developer wiki and issue tracker) into the site design. That is, of course, difficult, since Trac is written in Python and our site in PHP. Does anybody here know a way how to integrate a header and footer (PHP) into the Trac template (preferrably without invoking a - or rather two for header and footer - PHP process from the command line)?
Your Python code will have access to your users' cookies. A template would be best, but if you don't have one available (or the header/footer are trivially small, or whatever), you can simply port the PHP header and footer code to Python, using the cookies that are already there to query the database or whatever you need to do. If you want to retain your links for logging in, registering, and whatever else might be in the PHP version, simply link to the PHP side, then redirect back to Trac once PHP's done its job.
0
false
2
365
2009-12-15 17:26:21.320
Import error with virtualenv
I have a problem with virtualenv. I use it regulary, I use it on my development machine and on several servers. But on this last server I tried to use i got a problem. I created a virtualenv with the --no-site-packages argument, and then I installed some python modules inside the virtualenv. I can confirm that the modules is located inside the virtualenvs site-packages and everything seems to be fine. But when i try to do:source virtualenv/bin/activate and then import one of the module python import modulename i get an import error that says that the module doesnt exist. How is it that this is happending? It seems like it never activates even thoug that it says it do. Anybody have a clue on how to fix this?
Is there a bash alias active on this machine for "python", by any chance? That will take priority over the PATH-modifications made by activate, and could cause the wrong python binary to be used. Try running virtualenv/bin/python directly (no need to activate) and see if you can import your module. If this fixes it, you just need to get rid of your python bash alias.
1.2
true
1
366
2009-12-15 18:03:17.750
How to clean up my Python Installation for a fresh start
I'm developing on Snow Leopard and going through the various "how tos" to get the MySQLdb package installed and working (uphill battle). Things are a mess and I'd like to regain confidence with a fresh, clean, as close to factory install of Python 2.6. What folders should I clean out? What should I run? What symbolic links should I destroy or create?
when doing an "port selfupdate", rsync timesout with rsync.macports.org. There are mirror sites available to use.
0
false
2
367
2009-12-15 18:03:17.750
How to clean up my Python Installation for a fresh start
I'm developing on Snow Leopard and going through the various "how tos" to get the MySQLdb package installed and working (uphill battle). Things are a mess and I'd like to regain confidence with a fresh, clean, as close to factory install of Python 2.6. What folders should I clean out? What should I run? What symbolic links should I destroy or create?
My experience doing development on MacOSX is that the directories for libraries and installation tools are just different enough to cause a lot of problems that you end up having to fix by hand. Eventually, your computer becomes a sketchy wasteland of files and folders duplicated all over the place in an effort to solve these problems. A lot of hand-tuned configuration files, too. The thought of getting my environment set up again from scratch gives me the chills. Then, when it's time to deploy, you've got to do it over again in reverse (unless you're deploying to an XServe, which is unlikely). Learn from my mistake: set up a Linux VM and do your development there. At least, run your development "server" there, even if you edit the code files on your Mac.
0.101688
false
2
367
2009-12-16 01:04:08.380
Python: How do I find why IDLE restarts?
I am using python 2.5 on windows. All I am doing is unpickling a large file (18MB - a list of dictionaries) and modifiying some of its values. Now this works fine. But when I add a couple of prints, IDLE restarts. And weirdly enough it seems to be happening where I added the print. I figured this out commenting and uncommenting things line by line. I added a try catch around the print, but am not able to catch anything. When does IDLE restart? And how do I catch any exceptions or errors it throws(if it does)?
Enable the debugger and see if it tells you anything.
0
false
1
368
2009-12-16 04:11:41.030
deleter decorator using Property in Python
I'm playing around with property in Python and I was wondering how this @propertyName.deleter decorator works. I'm probably missing something, I could not find clear answers by Google. What I would like to achieve is when this deleter behavior is called, I can trigger other actions (e.g: using my 3d application SDK). For now just a simple print() doesn't seem to get triggered. Is deleter fired when I delete the property using del(instance.property) ? Otherwise, how can I achieve this? class M(): def __init__(self): self._m = None @property def mmm(self): return self._m @mmm.setter def mmm(self, val): self._m = val @mmm.deleter def mmm(self): print('deleting') # Not printing del(self._m) if __name__ == '__main__': i = M() i.mmm = 150 print(i.mmm) del(i.mmm) print(i.mmm) Thank you very much (:
In Python 3 you WOULD see the print's result -- and then an AttributeError for the last print (because _m has disappeared). You may be using Python 2.6, in which case you need to change the class clause to class M(object): to make M new-style, and then you'll get the same behavior as in Python 3.
0.999753
false
1
369
2009-12-16 04:44:50.613
Django: Where to put helper functions?
I have a couple of functions that I wrote that I need to use in my django app. Where would I put the file with them and how would I make them callable within my views?
If they are related to a specific app, I usually just put them in the related app folder and name the file, 'functions.py'. If they're not specific to an app, I make a commons app for components (tests, models, functions, etc) that are shared across apps.
0.996998
false
3
370
2009-12-16 04:44:50.613
Django: Where to put helper functions?
I have a couple of functions that I wrote that I need to use in my django app. Where would I put the file with them and how would I make them callable within my views?
I am using new python file service.py in app folder. The file contains mostly helper queries for specific app. Also I used to create a folder inside Django application that contains global helper functions and constants.
0.201295
false
3
370
2009-12-16 04:44:50.613
Django: Where to put helper functions?
I have a couple of functions that I wrote that I need to use in my django app. Where would I put the file with them and how would I make them callable within my views?
create a reusable app that include your generic functions so you can share between projects. use for example a git repo to store this app and manage deployments and evolution (submodule) use a public git repo so you can share with the community :)
0.999753
false
3
370
2009-12-16 23:00:08.263
split a pdf based on outline
i would like to use pyPdf to split a pdf file based on the outline where each destination in the outline refers to a different page within the pdf. example outline: main --> points to page 1 sect1 --> points to page 1 sect2 --> points to page 15 sect3 --> points to page 22 it is easy within pyPdf to iterate over each page of the document or each destination in the document's outline; however, i cannot figure out how to get the page number where the destination points. does anybody know how to find the referencing page number for each destination in the outline?
Darrell's class can be modified slightly to produce a multi-level table of contents for a pdf (in the manner of pdftoc in the pdftk toolkit.) My modification adds one more parameter to _setup_page_id_to_num, an integer "level" which defaults to 1. Each invocation increments the level. Instead of storing just the page number in the result, we store the pair of page number and level. Appropriate modifications should be applied when using the returned result. I am using this to implement the "PDF Hacks" browser-based page-at-a-time document viewer with a sidebar table of contents which reflects LaTeX section, subsection etc bookmarks. I am working on a shared system where pdftk can not be installed but where python is available.
0
false
1
371
2009-12-18 02:49:46.067
How to get the LAN IP that a socket is sending (linux)
I need some code to get the address of the socket i just created (to filter out packets originating from localhost on a multicast network) this: socket.gethostbyname(socket.gethostname()) works on mac but it returns only the localhost IP in linux... is there anyway to get the LAN address thanks --edit-- is it possible to get it from the socket settings itself, like, the OS has to select a LAN IP to send on... can i play on getsockopt(... IP_MULTICAST_IF...) i dont know exactly how to use this though...? --- edit --- SOLVED! send_sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 0) putting this on the send socket eliminated packet echos to the host sending them, which eliminates the need for the program to know which IP the OS has selected to send. yay!
quick answer - socket.getpeername() (provided that socket is a socket object, not a module) (playing around in python/ipython/idle/... interactive shell is very helpful) .. or if I read you question carefully, maybe socket.getsockname() :)
0
false
1
372
2009-12-18 15:55:10.657
Python GUI (glade) to display output of shell process
I'm writing a python application that runs several subprocesses using subprocess.Popen objects. I have a glade GUI and want to display the output of these commands (running in subprocess.Popen) in the gui in real time. Can anyone suggest a way to do this? What glade object do I need to use and how to redirect the output?
glade is only a program to build gui with gtk so when you ask for a glade object maybe you should ask for gtk widget and in this case textbuffer and textview chould be a solution or maybe treeview and liststore. subprocess.Popen has stdout and stderr arguments that can accept a file-like object. you can create an adapter that writes to the textbuffer or add items in the liststore
0.135221
false
1
373
2009-12-19 20:46:21.423
Rotating Proxies for web scraping
I've got a python web crawler and I want to distribute the download requests among many different proxy servers, probably running squid (though I'm open to alternatives). For example, it could work in a round-robin fashion, where request1 goes to proxy1, request2 to proxy2, and eventually looping back around. Any idea how to set this up? To make it harder, I'd also like to be able to dynamically change the list of available proxies, bring some down, and add others. If it matters, IP addresses are assigned dynamically. Thanks :)
Make your crawler have a list of proxies and with each HTTP request let it use the next proxy from the list in a round robin fashion. However, this will prevent you from using HTTP/1.1 persistent connections. Modifying the proxy list will eventually result in using a new or not using a proxy. Or have several connections open in parallel, one to each proxy, and distribute your crawling requests to each of the open connections. Dynamics may be implemented by having the connetor registering itself with the request dispatcher.
1.2
true
1
374
2009-12-20 08:52:40.370
how do I add a python module on MacOS X?
I'm trying to use pywn, a python library for using WordNet. I've played about with python a little under Windows, but am completely new at MacOS X stuff. I'm running under MacOS 10.5.8, so my default Python interpreter is 2.5.1 The pywn instructions say: "Put each of the .py files somewhere in your python search path." Where is the python search path defined under the default python installation in MacOS X? If I've put the pywn files in /Users/nick/programming/pywn, what is the best way of adding this to the search path? Is this the best place to put the files?
I think by default /Library/Python/2.5/site-packages/ is part of your search path. This directory is usually used for third party libraries.
1.2
true
1
375
2009-12-25 00:25:16.753
Start a "throwaway" MySQL session for testing code?
If I want to be able to test my application against a empty MySQL database each time my application's testsuite is run, how can I start up a server as a non-root user which refers to a empty (not saved anywhere, or in saved to /tmp) MySQL database? My application is in Python, and I'm using unittest on Ubuntu 9.10.
You can try the Blackhole and Memory table types in MySQL.
0
false
2
376
2009-12-25 00:25:16.753
Start a "throwaway" MySQL session for testing code?
If I want to be able to test my application against a empty MySQL database each time my application's testsuite is run, how can I start up a server as a non-root user which refers to a empty (not saved anywhere, or in saved to /tmp) MySQL database? My application is in Python, and I'm using unittest on Ubuntu 9.10.
--datadir for just the data or --basedir
1.2
true
2
376
2009-12-26 02:05:47.180
python source code conversion to uml diagram with Sparx Systems Enterprise Architect
Please let me know how to create a uml diagram along with its equivalent documentation for the source code(.py format) using enterprise architecture 7.5 Please help me find the solution, I have read the solution for the question on this website related to my topic but in vain
Go to project browser Create a model Right-click model > Add > Add View > Class Right-click class > Code Engineering > Import Source Directory... Check "one package per folder" The last one ensures you'll have an interesting diagram full of classes.
0.101688
false
2
377
2009-12-26 02:05:47.180
python source code conversion to uml diagram with Sparx Systems Enterprise Architect
Please let me know how to create a uml diagram along with its equivalent documentation for the source code(.py format) using enterprise architecture 7.5 Please help me find the solution, I have read the solution for the question on this website related to my topic but in vain
File / New Project / enter your project name. In the Project Browser, create a package named "source" Right-click the source package, "Code Engineering", "Import Source Directory". Pick the directory containing your module(s) as the "Root Directory" Set "Source Type" to Python Enable "Recursively Process Subdirectories" Select "Package Per File" Click "OK".
0.386912
false
2
377
2009-12-26 04:02:57.850
How do I make a simple file browser in wxPython?
I'm starting to learn both Python and wxPython and as part of the app I'm doing, I need to have a simple browser on the left pane of my app. I'm wondering how do I do it? Or at least point me to the right direction that'll help me more on how to do one. Thanks in advance! EDIT: a sort of side question, how much of wxPython do I need to learn? Should I use tools like wxGlade?
You can take a look at the wxPython examples, they also include code samples for almost all of the widgets supported by wxPython. If you use Windows they can be found in the Start Menu folder of WxPython.
0.135221
false
1
378
2009-12-29 23:15:55.703
Play Subset of audio file using Pyglet
How can I use the pyglet API for sound to play subsets of a sound file e.g. from 1 second in to 3.5seconds of a 6 second sound clip? I can load a sound file and play it, and can seek to the start of the interval desired, but am wondering how to stop playback at the point indicated?
It doesn't appear that pyglet has support for setting a stop time. Your options are: Poll the current time and stop playback when you've reached your desired endpoint. This may not be precise enough for you. Or, use a sound file library to extract the portion you want into a temporary sound file, then use pyglet to play that sound file in its entirety. Python has built-in support for .wav files (the "wave" module), or you could shell out to a command-line tool like "sox".
1.2
true
1
379
2010-01-02 03:19:49.930
Django: signal when user logs in?
In my Django app, I need to start running a few periodic background jobs when a user logs in and stop running them when the user logs out, so I am looking for an elegant way to get notified of a user login/logout query user login status From my perspective, the ideal solution would be a signal sent by each django.contrib.auth.views.login and ... views.logout a method django.contrib.auth.models.User.is_logged_in(), analogous to ... User.is_active() or ... User.is_authenticated() Django 1.1.1 does not have that and I am reluctant to patch the source and add it (not sure how to do that, anyway). As a temporary solution, I have added an is_logged_in boolean field to the UserProfile model which is cleared by default, is set the first time the user hits the landing page (defined by LOGIN_REDIRECT_URL = '/') and is queried in subsequent requests. I added it to UserProfile, so I don't have to derive from and customize the builtin User model for that purpose only. I don't like this solution. If the user explicitely clicks the logout button, I can clear the flag, but most of the time, users just leave the page or close the browser; clearing the flag in these cases does not seem straight forward to me. Besides (that's rather data model clarity nitpicking, though), is_logged_in does not belong in the UserProfile, but in the User model. Can anyone think of alternate approaches ?
Rough idea - you could use middleware for this. This middleware could process requests and fire signal when relevant URL is requested. It could also process responses and fire signal when given action actually succeded.
0
false
2
380
2010-01-02 03:19:49.930
Django: signal when user logs in?
In my Django app, I need to start running a few periodic background jobs when a user logs in and stop running them when the user logs out, so I am looking for an elegant way to get notified of a user login/logout query user login status From my perspective, the ideal solution would be a signal sent by each django.contrib.auth.views.login and ... views.logout a method django.contrib.auth.models.User.is_logged_in(), analogous to ... User.is_active() or ... User.is_authenticated() Django 1.1.1 does not have that and I am reluctant to patch the source and add it (not sure how to do that, anyway). As a temporary solution, I have added an is_logged_in boolean field to the UserProfile model which is cleared by default, is set the first time the user hits the landing page (defined by LOGIN_REDIRECT_URL = '/') and is queried in subsequent requests. I added it to UserProfile, so I don't have to derive from and customize the builtin User model for that purpose only. I don't like this solution. If the user explicitely clicks the logout button, I can clear the flag, but most of the time, users just leave the page or close the browser; clearing the flag in these cases does not seem straight forward to me. Besides (that's rather data model clarity nitpicking, though), is_logged_in does not belong in the UserProfile, but in the User model. Can anyone think of alternate approaches ?
The only reliable way (that also detects when the user has closed the browser) is to update some last_request field every time the user loads a page. You could also have a periodic AJAX request that pings the server every x minutes if the user has a page open. Then have a single background job that gets a list of recent users, create jobs for them, and clear the jobs for users not present in that list.
0.058243
false
2
380
2010-01-02 22:14:33.183
Upload file to a website via Python script
I want to upload a file from my computer to a file hoster like hotfile.com via a Python script. Because Hotfile is only offering a web-based upload service (no ftp). I need Python first to login with my username and password and after that to upload the file. When the file transfer is over, I need the Download and Delete-link (which is generated right after the Upload has finished). Is this even possible? If so, can anybody tell me how the script looks like or even give my hints how to build it? Thanks
You mention they do not offer FTP, but I went to their site and found the following: How to upload with FTP? ftp.hotfile.com user: your hotfile username pass: your hotfile password You can upload and make folders, but cant rename,move files Try it. If it works, using FTP from within Python will be a very simple task.
0
false
1
381
2010-01-03 10:14:58.217
how to start a thread when django runserver?
I want to start a thread when django project runserver successfully. where can I put the create-thread-and-start code? Is there any hook for the django runserver?
Why would you want to do that? runserver is for development only, it should never be used in production. And if you're running via Apache, it should manage threads/processes for you anyway.
0.998178
false
2
382
2010-01-03 10:14:58.217
how to start a thread when django runserver?
I want to start a thread when django project runserver successfully. where can I put the create-thread-and-start code? Is there any hook for the django runserver?
Agree with the above answer, you probably don't want to do this. Runserver should be used for development only. Once you deploy, you'll want to move to Apache/WSGI. On my dev machine (where I do use runserver), I usually throw it in a screen session, so it doesn't get in the way, but I can pull it back up if I need to see a traceback.
0
false
2
382
2010-01-05 17:36:48.483
How to use C# client to consume Django/Python web service (all methods are returning null)?
I have a C# command-line client that I'm testing the consumption of SOAP/WSDL via Django/Python/soaplib created WSDL. I've managed to successfully connect to the web service by adding a service reference. I then call one of service's methods, and the service processes the data I send, but it returns null instead of the integer I'm expecting. Any ideas on how to get back something other than a null response? Thanks for any help or suggestions!
We faced the similar problem while consuming a web service it was the type of data returned we were getting data in UTF-16 format. Please check if you have proper data type in use.
0
false
2
383
2010-01-05 17:36:48.483
How to use C# client to consume Django/Python web service (all methods are returning null)?
I have a C# command-line client that I'm testing the consumption of SOAP/WSDL via Django/Python/soaplib created WSDL. I've managed to successfully connect to the web service by adding a service reference. I then call one of service's methods, and the service processes the data I send, but it returns null instead of the integer I'm expecting. Any ideas on how to get back something other than a null response? Thanks for any help or suggestions!
One thing you can do is start by building a manual proxy using WebClient, or WebRequest/WebResponse. Construct your manual proxy to send the desired data to the WS for testing. Couple of things to check on the WSDL implementation: The WSDL definition needs to match exactly, including case, for the C# proxy to recognize the values Namespace definitions need to match exactly, including trailing slashes Check the profile of the generated proxy and make sure it conforms with what your desired profile is (i.e. basic or none if needed) If you post your generated proxy we can look at it and see if there is anything out of the ordinary.
0
false
2
383
2010-01-06 00:47:29.197
Speeding up the python "import" loader
I'm getting seriously frustrated at how slow python startup is. Just importing more or less basic modules takes a second, since python runs down the sys.path looking for matching files (and generating 4 stat() calls - ["foo", "foo.py", "foo.pyc", "foo.so"] - for each check). For a complicated project environment, with tons of different directories, this can take around 5 seconds -- all to run a script that might fail instantly. Do folks have suggestions for how to speed up this process? For instance, one hack I've seen is to set the LD_PRELOAD_32 environment variable to a library that caches the result of ENOENT calls (e.g. failed stat() calls) between runs. Of course, this has all sorts of problems (potentially confusing non-python programs, negative caching, etc.).
Something's missing from your premise--I've never seen some "more-or-less" basic modules take over a second to import, and I'm not running Python on what I would call cutting-edge hardware. Either you're running on some seriously old hardware, or you're running on an overloaded machine, or either your OS or Python installation is broken in some way. Or you're not really importing "basic" modules. If it's any of the first three issues, you need to look at the root problem for a solution. If it's the last, we really need to know what the specific packages are to be of any help.
0.081452
false
3
384
2010-01-06 00:47:29.197
Speeding up the python "import" loader
I'm getting seriously frustrated at how slow python startup is. Just importing more or less basic modules takes a second, since python runs down the sys.path looking for matching files (and generating 4 stat() calls - ["foo", "foo.py", "foo.pyc", "foo.so"] - for each check). For a complicated project environment, with tons of different directories, this can take around 5 seconds -- all to run a script that might fail instantly. Do folks have suggestions for how to speed up this process? For instance, one hack I've seen is to set the LD_PRELOAD_32 environment variable to a library that caches the result of ENOENT calls (e.g. failed stat() calls) between runs. Of course, this has all sorts of problems (potentially confusing non-python programs, negative caching, etc.).
zipping up as many pyc files as feasible (with proper directory structure for packages), and putting that zipfile as the very first entry in sys.path (on the best available local disk, ideally) can speed up startup times a lot.
0.715303
false
3
384
2010-01-06 00:47:29.197
Speeding up the python "import" loader
I'm getting seriously frustrated at how slow python startup is. Just importing more or less basic modules takes a second, since python runs down the sys.path looking for matching files (and generating 4 stat() calls - ["foo", "foo.py", "foo.pyc", "foo.so"] - for each check). For a complicated project environment, with tons of different directories, this can take around 5 seconds -- all to run a script that might fail instantly. Do folks have suggestions for how to speed up this process? For instance, one hack I've seen is to set the LD_PRELOAD_32 environment variable to a library that caches the result of ENOENT calls (e.g. failed stat() calls) between runs. Of course, this has all sorts of problems (potentially confusing non-python programs, negative caching, etc.).
The first things that come to mind are: Try a smaller path Make sure your modules are pyc's so they'll load faster Make sure you don't double import, or import too much Other than that, are you sure that the disk operations are what's bogging you down? Is your disk/operating system really busy or old and slow? Maybe a defrag is in order?
0.3154
false
3
384
2010-01-06 15:09:00.097
Django: How should I store a money value?
I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this: PayPal requires 2 decimal places, so if I have a product that is 49 dollars even, PayPal wants to see 49.00 come across the wire. Django's DecimalField() doesn't set a decimal amount. It only stores a maximum decimal places amount. So, if you have 49 in there, and you have the field set to 2 decimal places, it'll still store it as 49. I know that Django is basically type casting when it deserializes back from the database into a Decimal (since Databases don't have decimal fields), so I'm not completely concerned with the speed issues as much as I am with the design issues of this problem. I want to do what's best for extensibility. Or, better yet, does anyone know how to configure a django DecimalField() to always format with the TWO_PLACES formatting style.
You store it as a DecimalField and manually add the decimals if you need to, as Valya said, using basic formatting techniques. You can even add a Model Method to you product or transaction model that will spit out the DecimalField as an appropriately formatted string.
0.040794
false
2
385
2010-01-06 15:09:00.097
Django: How should I store a money value?
I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this: PayPal requires 2 decimal places, so if I have a product that is 49 dollars even, PayPal wants to see 49.00 come across the wire. Django's DecimalField() doesn't set a decimal amount. It only stores a maximum decimal places amount. So, if you have 49 in there, and you have the field set to 2 decimal places, it'll still store it as 49. I know that Django is basically type casting when it deserializes back from the database into a Decimal (since Databases don't have decimal fields), so I'm not completely concerned with the speed issues as much as I am with the design issues of this problem. I want to do what's best for extensibility. Or, better yet, does anyone know how to configure a django DecimalField() to always format with the TWO_PLACES formatting style.
I suggest to avoid mixing representation with storage. Store the data as a decimal value with 2 places. In the UI layer, display it in a form which is suitable for the user (so maybe omit the ".00"). When you send the data to PayPal, format it as the interface requires.
0.386912
false
2
385
2010-01-06 17:57:47.400
How does one do async ajax calls using cherrypy?
I'm using cherrypy's standalone server (cherrypy.quickstart()) and sqlite3 for a database. I was wondering how one would do ajax/jquery asynchronous calls to the database while using cherrypy?
The same way you would do them using any other webserver - by getting your javascript to call a URL which is handled by the server-side application.
1.2
true
1
386
2010-01-07 12:45:37.600
how do i get the byte count of a variable in python just like wc -c gives in unix
i am facing some problem with files with huge data. i need to skip doing some execution on those files. i get the data of the file into a variable. now i need to get the byte of the variable and if it is greater than 102400 , then print a message. update : i cannot open the files , since it is present in a tar file. the content is already getting copied to a variable called 'data' i am able to print contents of the variable data. i just need to check if it has more than 102400 bytes. thanks
This answer seems irrelevant, since I seem to have misunderstood the question, which has now been clarified. However, should someone find this question, while searching with pretty much the same terms, this answer may still be relevant: Just open the file in binary mode f = open(filename, 'rb') read/skip a bunch and print the next byte(s). I used the same method to 'fix' the n-th byte in a zillion images once.
0
false
2
387
2010-01-07 12:45:37.600
how do i get the byte count of a variable in python just like wc -c gives in unix
i am facing some problem with files with huge data. i need to skip doing some execution on those files. i get the data of the file into a variable. now i need to get the byte of the variable and if it is greater than 102400 , then print a message. update : i cannot open the files , since it is present in a tar file. the content is already getting copied to a variable called 'data' i am able to print contents of the variable data. i just need to check if it has more than 102400 bytes. thanks
len(data) gives you the size in bytes if it's binary data. With strings the size depends on the encoding used.
0.081452
false
2
387
2010-01-07 16:14:40.953
how to make fillable forms with reportlab in python
can anyone please help me with creating forms in python using the reportlab lib. i am totally new to this and i would appreciate sample code thanks
Apparently reportlab does not support creating fillable pdf forms. The only thing I found about it being present in the API dates from 2003, afterwards all statements clearly say no. I'm answering this so late because this is one of the highest hits when you enter 'reportlab forms' in google. I do agree with Travis you should google easy questions yourself, but this isn't really clearly answered anywhere.
0.999998
false
1
388