Q_Id
int64
337
49.3M
CreationDate
stringlengths
23
23
Users Score
int64
-42
1.15k
Other
int64
0
1
Python Basics and Environment
int64
0
1
System Administration and DevOps
int64
0
1
Tags
stringlengths
6
105
A_Id
int64
518
72.5M
AnswerCount
int64
1
64
is_accepted
bool
2 classes
Web Development
int64
0
1
GUI and Desktop Applications
int64
0
1
Answer
stringlengths
6
11.6k
Available Count
int64
1
31
Q_Score
int64
0
6.79k
Data Science and Machine Learning
int64
0
1
Question
stringlengths
15
29k
Title
stringlengths
11
150
Score
float64
-1
1.2
Database and SQL
int64
0
1
Networking and APIs
int64
0
1
ViewCount
int64
8
6.81M
10,210,233
2012-04-18T13:19:00.000
0
0
1
0
python,list,class,function,contains
10,210,281
4
false
0
0
It depends on the class how it does the check. For the builtin list it uses the == operator; otherwise you couldn't e.g. use 'something' in somelist safely. To be more specific, it check if the item is equal to an item in the list - so internally it's most likely a hash(a) == hash(b) comparison; if the hashes are equal the objects itself are probably compared, too.
1
13
0
Does the __contains__ method of a list class check whether an object itself is an element of a list, or does it check whether the list contains an element equivalent to the given parameter? Could you give me an example to demonstrate?
Python List Class __contains__ Method Functionality
0
0
0
6,929
10,212,293
2012-04-18T15:06:00.000
1
0
0
0
python,google-app-engine,http-status-codes
10,212,363
2
false
1
0
I might be wrong but there is no such thing as incoming request status code, application doing requests in case of redirect gets 302 from initial request checks location and do another request. And history of incoming request in shape of thing like "traceroute" just don't exists in HTTP.
1
0
0
How can I check the status code of a request? I want to check what kind of redirects were used to access a page. For response objects I would use *response.status_code*
How to determine status code of request
0.099668
0
1
111
10,212,442
2012-04-18T15:14:00.000
-15
0
1
0
python
10,212,669
2
false
0
0
No there is not a duplicate code checker, as there is no way to easily distinguish whether it has repeated or not because depending on the program, there may be dependencies on the code that is "duplicated" and things may be overwritten, ect. . All in all, no, there is no duplicate code checker that i know of for python. However, the use of a better IDE that tracks variable usage may be helpful in this case. :)
1
21
0
Is there any library in python for duplicate code checker? I use python IDE and I am finding trouble refactoring my code. Are there any python library available which suggest duplicate code in the program/project? Update: I found clone digger which as per its site, We have tested Clone Digger on sources of several open-source projects. There are following drawbacks of the current report format: Differences are highlighted using diff algorithm. This way of highlighting has nothing common with the abstract syntax tree based algorithm of comparing sequences of statements for similarity. Class and function comments are taken into account during the computation of similarity, but they are not presented in the output. Therefore some clone pairs can look equal but marked as convergent. Are there any tools better than this?
Removing duplicate code in python
-1
0
0
8,400
10,212,791
2012-04-18T15:32:00.000
1
0
0
0
python,django,facebook,celery,django-signals
10,213,618
1
false
1
0
This really comes down to synchronous vs asynchronous. Django signals are synchronous that is they will block the response until they are completed. Celery tasks are asynchronous. Which will be better will depend on whether the benefits of handling the profile building asynchronously outweighs the negatives of the maintaining the extra infrastructure necessary for celery. It's basically impossible to answer this without a lot more specific information regarding the specifics of your situation.
1
0
0
I recently started playing around with django-social-auth and am looking for some help from the community to figure out the best way to move forward with an idea. Once a user has registered you have access to his oauth token which allows you to pull certain data. In my case I want to build a nice little profile based on the users avatar, location and maybe some other information if it's available. Would the best way be to: build a custom task for celery and pull the information and build the profile? or, make use of signals to build the profile?
django-social-auth profile builder
0.197375
0
0
210
10,214,771
2012-04-18T17:33:00.000
0
0
1
0
python,function,ipython
19,082,190
4
false
0
0
Fumctions in IPython are considered dynamically generated if: they are metaprogrammed - they are created by another function. in this case ther is no source code, it simply does not exist. they are referenced in a different namespace to which they were created and there is no information as to what namespace they are originally in. in this case find out where they originally were and run ?? from there.
1
7
0
In an IPython session, I usually define custom functions...problem is, sometimes I want to see the actual code for these functions. So far, I have not been able to find a way to display this. Using ? and ?? simply returns "Dynamically generated function. No source code available." Is there any way to display source code for user-defined functions?
How to show source code for dynamically created ("custom") function in IPython?
0
0
0
893
10,214,827
2012-04-18T17:37:00.000
0
0
1
0
python,pip
57,027,462
16
false
0
0
In question, it is not mentioned which OS user is using (Windows/Linux/Mac) As there are couple of answers which will work flawlessly on Mac and Linux. Below command can be used in case the user is trying to find the version of a python package on windows. In PowerShell use below command : pip list | findstr <PackageName> Example:- pip list | findstr requests Output : requests 2.18.4
1
976
0
Using pip, is it possible to figure out which version of a package is currently installed? I know about pip install XYZ --upgrade but I am wondering if there is anything like pip info XYZ. If not what would be the best way to tell what version I am currently using.
Find which version of package is installed with pip
0
0
0
993,511
10,217,708
2012-04-18T20:47:00.000
1
0
0
0
python,web-crawler,scrapy
10,217,884
3
false
1
0
This has nothing to do with download speed. XPath //* selects the entire page. XPath //script/text() selects only text inside script elements. So of course the second one is faster, because there is less text to search with the re() call!
3
0
0
I am using Scrapy crawler to crawl over 100k pages website. The speed is the big concern in this case. Today I noticed that hxs.select('//*').re('something') is way slower than hxs.select('//script/text()').re('something'). Can any expert explain to me why? As I understand, the crawler should download the entire page no matter what xpath selector I use. So the xpath should not affect the speed much at all. Thanks a lot for any tips.
How does xpathselector affect the speed of scrapy crawl running?
0.066568
0
1
410
10,217,708
2012-04-18T20:47:00.000
0
0
0
0
python,web-crawler,scrapy
10,248,266
3
false
1
0
XPath definitely has a role in crawler speed, crawler download the page, but Xpath process the Html that crawler downloaded. so if the page is big then xpath will take time to process whole Html.
3
0
0
I am using Scrapy crawler to crawl over 100k pages website. The speed is the big concern in this case. Today I noticed that hxs.select('//*').re('something') is way slower than hxs.select('//script/text()').re('something'). Can any expert explain to me why? As I understand, the crawler should download the entire page no matter what xpath selector I use. So the xpath should not affect the speed much at all. Thanks a lot for any tips.
How does xpathselector affect the speed of scrapy crawl running?
0
0
1
410
10,217,708
2012-04-18T20:47:00.000
1
0
0
0
python,web-crawler,scrapy
10,217,990
3
false
1
0
I am afraid that you might look for 'something' in the entire document, so you probably should still use hxs.select('//*').re('something'). And about the speed question: the answer is that if you look for the word 'something' in a document which is 4k large, of course it will take longer then filtering the document for text() and after looking for that word within that text.
3
0
0
I am using Scrapy crawler to crawl over 100k pages website. The speed is the big concern in this case. Today I noticed that hxs.select('//*').re('something') is way slower than hxs.select('//script/text()').re('something'). Can any expert explain to me why? As I understand, the crawler should download the entire page no matter what xpath selector I use. So the xpath should not affect the speed much at all. Thanks a lot for any tips.
How does xpathselector affect the speed of scrapy crawl running?
0.066568
0
1
410
10,217,948
2012-04-18T21:02:00.000
1
0
0
1
python,google-app-engine,analytics,visitors
10,221,347
3
false
1
0
There is no way to tell when someone stops viewing a page unless you use Javascript to inform the server when that happens. Forums etc typically assume that someone has stopped viewing a page after n minutes of inactivity, and base their figures on that. For minimal resource use, I would suggest using memcache exclusively here. If the value gets evicted, the count will be incorrect, but the consequences of that are minimal, and other solutions will use a lot more resources.
1
2
0
I need to get the number of unique visitors(say, for the last 5 minutes) that are currently looking at an article, so I can display that number, and sort the articles by most popular. ex. Similar to how most forums display 'There are n people viewing this thread' How can I achieve this on Google App Engine? I am using Python 2.7. Please try to explain in a simple way because I recently started learning programming and I am working on my first project. I don't have lots of experience. Thank you!
How to get number of visitors of a page on GAE?
0.066568
0
0
1,919
10,218,679
2012-04-18T21:59:00.000
1
1
0
0
python,selenium
10,218,792
6
false
1
0
My experience has been that any sufficiently useful test framework will end up needing a customized logging solution. You are going to end up wanting domain specific and context relevant information, and the pre-baked solutions never really fit the bill by virtue of being specifically designed to be generic and broadly applicable. If you are already using Python, I'd suggest looking in to the logging module and learning how to write Handlers and Formatters. It's actually pretty straight forward, and you will end up getting better results than trying to shoehorn the logging you need in to some selenium-centric module.
1
7
0
I am doing some R&D on selenium+python. I wrote some test cases in python using selenium webdriver and unittest module. I want to know how can I create report of the test cases. Is there inbuilt solution available in selenium or I need to code to generate file. Or is there any other web testing framework with javascript support available in python which have reporting functionality. I am basically new to python as well as selenium. Just trying to explore.
Selenium+python Reporting
0.033321
0
1
24,481
10,219,934
2012-04-19T00:13:00.000
0
0
0
1
python,django,queue
10,219,986
1
true
1
0
Looks like duplicate imports in my project were causing the problems.
1
0
0
When djutils goes through autodiscover in the init, it imports my task "app.commands.task1" and states this as part of the output of the log. But when I run webserver and try to queue the command, the queue_consumer log indicates that it cannot find the key "project.app.commands.queuecmd_task1" QueueException: project.app.commands.queuecmd_task1 not found in CommandRegistry I assume that the fact that the string it is trying to find has "project" prepended is the reason it cannot find the task. Why would that be happening?
djutils autodiscover importing command without top level parent, queue_consumer doesn't like it
1.2
0
0
35
10,220,654
2012-04-19T01:59:00.000
5
0
1
0
java,python,list
10,220,713
6
true
0
0
You can use Arrays.asList then use List.indexOf. The other suggestions to use Arrays.binarySearch are good but require the array to be sorted.
1
0
0
For Python, I can do something like array.index(element) to get the index for an element in array. How can I do this in Java using regular arrays, not arrayList? Is there a similar function?
Java array analog for python list.index()?
1.2
0
0
257
10,220,943
2012-04-19T02:41:00.000
0
1
0
0
python,windows
10,220,978
4
false
0
0
raw_input('Please fill in questionnaire 1 and press [ENTER] when you are done.') will wait for someone to hit [enter]. Clearing the screen may be OS/environment dependent, I am not sure.
1
0
0
'lo, I am currently trying to code a simple routine for an experiment we are planning to run. The experiment starts by entering a subject number and creating a bunch of files. I got that part working. Next, we want the screen to go blank and display a message. Something like 'Please fill in questionnaire 1 and press [ENTER] when you are done.' My question is, how do you recommend I present a blank screen with a message like that that waits for a certain key to be pressed? I have quite some programming experience but haven't worked with Python before so any hints are greatly appreciated. Thanks a lot in advance for your time! ~~~~~~~~~~~~~~~~~~ Some extra info that might be relevant: We are running this on Windows XP (Service Pack 2) computers. The whole point of this is that the participant does not have access to the desktop or anything on the computer basically. We want the experiment to start and display a bunch of instructions on the screen that the subject has to follow without them being able to abort etc. Hope this makes sense.
Present blank screen, wait for key press -- how?
0
0
0
5,401
10,221,441
2012-04-19T03:55:00.000
2
0
1
0
python,function
10,221,621
2
false
0
0
In general import multiprocessing multiprocessing.__path__ multiprocessing.__file__ __path__ yields location of the library __file__ yields complete path of the file. If above didn't work, you need to look into python development source code. Regarding type source code, Raymond Hettinger's answer is correct.
1
2
0
I have used type() function in my program... I just want to know how does Python implement this? Or where could I find the source code file that implement this function?
source code of python inbuilt functions
0.197375
0
0
2,787
10,222,493
2012-04-19T06:05:00.000
2
0
0
0
python,xml,openerp
10,224,838
1
true
1
0
No you cannot do that: the field names are keys in a Python dictionary, in what you write the second invoice_line will overwrite the first one this would mess up OpenERP's ORM anyway as it does not handle relations to different tables. So you need two different columns, one relative to account.invoice.line and the other to account.service.line. If you really need a merged view, then you can add a function field which will return the union of the invoice and service lines found by the two previous fields. But I'm not sure the forms will be able to handle this.
1
0
0
I try to create a related field on OpenERP 6.0.1 . is it possible to define two different onetomany relationfor the same field name? What all changes i must do in the(.py file and XML Files).
onetomany relation field in Openerp
1.2
0
1
759
10,223,003
2012-04-19T06:53:00.000
1
0
0
1
python,design-patterns,twisted
10,223,666
1
true
0
0
Twisted havs a package "twisted.words.xish.utility.EventDispatcher", pydoc it to know the usage, it is simple. However, I think what make Twisted strong is its "Deferred". You can looks Deferred object as a Closure of related events (something OK, something failed), callback, fallback are registed observer function. Deferred has advanced feature, such as can be nested. So in my opinion, you can use default EventDispatcher in Twisted, or invent some simple new. But If you introduce some complicated mechanism into Twisted, it dooms to lead a confusion and mess.
1
1
0
I just wanted to hear ideas on correct usage of EventListener/EventSubscription provider in twisted. Most of the examples and the twisted source handle events through the specific methods with a pretty hard coupling. Dispatching target methods of those events are "hardcoded" in a specific Protocol class and then it is a duty of inheriting class to override these to receive the "event". This is very nice and transparent to use while we know of all of potential subscribers when creating the Protocol. However in larger projects there is a need (perhaps I am in a wrong mindset) for a more dynamic event subscription and subscription removal: think of hundereds of object with a lifespan of a minute all interested in the same event. What would be correct way to acheive this according to the "way of twisted". I currently have created an event subscription / dispatching mechanism, however there is a lingering thought that the lack of this pattern in twisted library might suggest that there is a better way.
EventListener mechanism in twisted
1.2
0
0
389
10,224,384
2012-04-19T08:32:00.000
0
0
1
1
java,python
10,224,419
2
false
0
0
Import all the files in Eclipse. If you manage to get the code compile using the refactor functions of the IDE it will save you all the trouble. There is no functionality of adding synonyms to the imports in java, but even if there was such how would that have helped you? You still will need to change all your files.
1
1
0
I have a bunch of idl files that automatically create four packages, with a lot of java files into it. I need to insert those java files in a com.bla. package architecture. Thing is in my generated files I have imports UCO.State for example, that do not fit with my new package architecture. So question is : Is there a java equivalent to 'import com.bla as bla' ? The only other option I see is to import the UCO package and rename all UCO.State and other directly by State. But that would mean refactoring hundreds of files o_O. Any idea ? Thanks !
python import as equivalent in Java?
0
0
0
982
10,227,042
2012-04-19T11:28:00.000
2
0
0
1
google-app-engine,python-2.7,blobstore
10,227,981
1
true
0
0
Try checking for user IP at the point where you generate upload url via create_upload_url(). The upload handler is actually called by Blobstore upload logic after the upload is done, hence the strange IP.
1
1
0
I'm attempting to get the user's IP from inside of my upload handler, but it seems that the only IP supplied is 0.1.0.30. Is there any way around this or any way to get the user's actual IP from inside of the upload handler?
How can I get a user's IP from a Blobstore upload handler?
1.2
0
1
204
10,228,275
2012-04-19T12:39:00.000
6
0
1
0
python
10,228,323
5
false
0
0
it prevents the Python interpreter from attaching any special meanings to special characters in the string (such as the backslash), and just interpret it as is (i.e., in its "raw" form). This is one way you can "escape" special characters in strings you use. You'll often see raw strings in path specifications. Let's say the path contains a directory that starts with t, e.g., c:\tests\data.csv, so you'd not want \t to be interpreted as a tab, hence use the r modifier.
4
3
0
This has probably answered somewhere at sometime but the titles I have seen don't connect so here it goes. I have seen python commands that read os.listdir(r".\bootstrapper"). What is the 'r' doing? Cheers...
'r' in Python commands
1
0
0
5,636
10,228,275
2012-04-19T12:39:00.000
1
0
1
0
python
10,228,303
5
false
0
0
It makes it a raw string. In other words, backslashes will be preserved. '\n' is interpreted as a new-line, but r'\n' is interpreted as the literal characters '\' and 'n'. Also note that occasionally you'll see u'string' if you're using python2.x code. This implies that the string should be interpreted as a unicode string. (in python 3.x, all strings are interpreted as unicode)
4
3
0
This has probably answered somewhere at sometime but the titles I have seen don't connect so here it goes. I have seen python commands that read os.listdir(r".\bootstrapper"). What is the 'r' doing? Cheers...
'r' in Python commands
0.039979
0
0
5,636
10,228,275
2012-04-19T12:39:00.000
3
0
1
0
python
10,228,297
5
false
0
0
r marks raw input. This means that the normal escape characters within the string are ignored (like \ )
4
3
0
This has probably answered somewhere at sometime but the titles I have seen don't connect so here it goes. I have seen python commands that read os.listdir(r".\bootstrapper"). What is the 'r' doing? Cheers...
'r' in Python commands
0.119427
0
0
5,636
10,228,275
2012-04-19T12:39:00.000
1
0
1
0
python
11,424,906
5
false
0
0
r means raw input. If a string is marked as r, then the meaning of any special character whithin the string will be ignored, the most frequently situation will be the backslash.
4
3
0
This has probably answered somewhere at sometime but the titles I have seen don't connect so here it goes. I have seen python commands that read os.listdir(r".\bootstrapper"). What is the 'r' doing? Cheers...
'r' in Python commands
0.039979
0
0
5,636
10,228,596
2012-04-19T12:57:00.000
0
0
0
0
python,plone,ploneformgen
10,232,165
2
false
1
0
As I recall, PFG submissions don't generate Plone events. While you could potentially modify PFG (or better yet, contribute enhancements) to add events on form submission, I think the use-case you are describing is probably better realized by building a custom content type to represent your Leave Application Form. While this is slightly more work than building a PFG form, you can then easily take advantage of workflow, events, content rules, etc.
2
1
0
how to trigger a content rule if PloneFormGen's form data is submitted in Plone 4.1. eg. I have created a Leave application form for employees. Once the employee submits data, the content rule should send the leave data to his manager. If he approves, final approval should be taken from the General Manager(GM). if the intermediate manager rejects, mail is sent to the employee directly. If approved by GM , mail is sent to employee directly. I want reviewer at 2 or 3 levels with different states.I am unable to define the states and transitions correctly. Can anybody guide?
how to trigger a content rule if PloneFormGen's form data is submitted in Plone 4.1
0
0
0
173
10,228,596
2012-04-19T12:57:00.000
2
0
0
0
python,plone,ploneformgen
10,234,004
2
true
1
0
Use uwosh.pdf.d2c to store the content submissions as actual plone content. Then you can use content rules on those objects.
2
1
0
how to trigger a content rule if PloneFormGen's form data is submitted in Plone 4.1. eg. I have created a Leave application form for employees. Once the employee submits data, the content rule should send the leave data to his manager. If he approves, final approval should be taken from the General Manager(GM). if the intermediate manager rejects, mail is sent to the employee directly. If approved by GM , mail is sent to employee directly. I want reviewer at 2 or 3 levels with different states.I am unable to define the states and transitions correctly. Can anybody guide?
how to trigger a content rule if PloneFormGen's form data is submitted in Plone 4.1
1.2
0
0
173
10,230,820
2012-04-19T14:55:00.000
23
0
1
0
python,ipython,multiline,paste
10,522,299
2
false
0
0
Type %paste into the IPython command line.
2
12
0
I used IPython in the past and I used to be able to copy and paste multi-line commands, e.g., a for loop in IPython. Working in my new PC after installing Python(x,y) 2.7.2.1, I can paste multi-line snippets by using Right-click → Edit → Paste but not by using CTRL+P, as I used to do. When using CTRL+P only the first line for the multi-line snippet gets pasted. Can somebody help please? I looked in the settings and documentation to no avail.
Paste Multi-line Snippets into IPython
1
0
0
8,856
10,230,820
2012-04-19T14:55:00.000
16
0
1
0
python,ipython,multiline,paste
48,710,809
2
false
0
0
You can use %cpaste with IPython shell (which is also what is used by Django's management shell). If you want to learn more of the features, type %quickref.
2
12
0
I used IPython in the past and I used to be able to copy and paste multi-line commands, e.g., a for loop in IPython. Working in my new PC after installing Python(x,y) 2.7.2.1, I can paste multi-line snippets by using Right-click → Edit → Paste but not by using CTRL+P, as I used to do. When using CTRL+P only the first line for the multi-line snippet gets pasted. Can somebody help please? I looked in the settings and documentation to no avail.
Paste Multi-line Snippets into IPython
1
0
0
8,856
10,231,221
2012-04-19T15:15:00.000
0
0
0
0
python,django,download
10,248,076
1
false
1
0
In such cases, I usually return an archived file to user with HttpResponse and set the content type to "attachment". This way the download starts automatically and I don't have to save the archived file. Is this approach helps you or not?
1
1
0
In my server side code in Django, i download a set of files on the server and create an archive which is then sent to the client side for download. Is there a way i can automatically delete this archive once the download on the client side is complete or aborted ? Thank You
Automatically deleting archive on server in Django when client side download completes
0
0
0
113
10,232,673
2012-04-19T16:36:00.000
14
0
0
0
python,django,web-services
25,833,953
5
false
1
0
AWS : Free tier available great support(but for technical help you got to pay) can use platform (PAAS) BeanStalk can customize architecture in case you get a dedicated instance great community of support Custom domain great documentation can SSH Most popular Heroku:(Django) Free to some extent Can use only POSTgresql in free plan git must Good support easy to start custom domain Can use bash in production(Not SSH).. cannot make direct changes in production. This is what makes your App stable. Any change/update goes through git. code maintenance - good (deployment through git heroku commands only) use AWS S3 to store static files Temporary files are removed perodically Once you scale that they start to bill, it is really costly. Since this is a PAAS, you have got what you have got. It takes lots of efforts to customize(to some extent) the architecture of the APP. Google App Engine:( Flask/Django project.) Free to some extent very easy to start(hello world app) custom domain code maintenance - good (automatic deployment) Support is not available Pythonanywhere: Free to some extent No custom domain in free plan easy to use Good support Webfaction:(Django) Not free.. (I think (minimal plan) costs 10 $ per month on shared hosting. ) SSH available custom domain Architecture customization. Good support
1
15
0
Hi I'm looking for some advice I currently own a resseller package with Heart internet as I host a few personal websites. However I'm currently learning Django (The python Framework) and want to be able to host my own server. I have been setting up virtual servers to play around with. Anyway to have SSH access you have to send in and ask them to open it for you, in the meantime of asking them if it was possible to install Django / set up SSH access i was advised that i can't use Django unless i purchase a Virtual machine even though Python is intalled on the server. Surley i can install Django onto my server if i have SSH access? Has anyone else has a similair issue? Or can anyone advise me on what to do.. The last thing i was to do is spend more money with them. Thanks.
Hosting my Django site
1
0
0
29,244
10,233,088
2012-04-19T17:01:00.000
4
0
1
0
javascript,parameters,python-sphinx
10,245,168
1
false
1
0
You need to add a blank line between the directive and its options.
1
3
0
I get the following error using the js:function directive. Why doesn't :param recognise multiple values between ::? " invalid option data: extension option field name may not contain multiple words. .. js:function:: f(test,test2) :param test: :param test2: "
sphinx js:function directive doesn't recognise params
0.664037
0
0
423
10,233,187
2012-04-19T17:08:00.000
0
0
0
0
php,python,mysql,django,cakephp
10,233,231
2
false
1
0
This is one of the reasons to use RDBMS to provide access for different users and applications to the same data. There should absolutely no problem with this.
1
0
0
I have a web application that has been done using Cakephp with MySql as the DB. The webapp also exposes a set of web services that get and update data to the MySQL DB. I will like to extend the app to provide a fresh set of web services but will like to use a python based framework like web2py/django etc. Since both will be working of the same DB will it cause any problems? The reason I want to do it is because the initial app/web services was done by somebody else and now I want to extend it and am more comfortable using python/web2py that php/cakephp.
Same MySql DB working with a php and a python framework
0
1
0
73
10,234,885
2012-04-19T18:55:00.000
1
0
0
0
javascript,detect,python-idle
10,234,996
5
false
0
0
Store their last activity in a database table when they are active. You can use mouse movement, keypresses, or some other activity to update the timestamp. Periodically poll that table with an ajax call on the page on which the user would see their online/offline status. If the last active time is > 5 minutes, show them as offline or idle.
3
3
0
I have a script that sends a time-sensitive notification to users when there is a new question directed to them. However, I found that some people leave their computers open and go grab lunch, therefore missing notifications. I'm looking to put together a script that detects if the user is idle for 5 minutes, and if so, it would show them as 'offline' and close down notifications. I was curious if it is possible to detect inactivity even across tabs? (for example if a user switches to another tab to Facebook.com and stays active there, they would be seen as 'active' even though they are not on our webpage specifically).
Is it possible to detect idle time even across tabs?
0.039979
0
1
3,773
10,234,885
2012-04-19T18:55:00.000
2
0
0
0
javascript,detect,python-idle
10,235,006
5
true
0
0
Everything that happens when the user is NOT on your side is impossible to track (luckily). So not this is not possible (think about the security). UPDATE Now that I think of it. It is possible, however very unlikely that you can do it. If your name would have been Google you would have come a long way, because lots of websites use Google analytics. But other than that: NO not possible for reasons mentioned.
3
3
0
I have a script that sends a time-sensitive notification to users when there is a new question directed to them. However, I found that some people leave their computers open and go grab lunch, therefore missing notifications. I'm looking to put together a script that detects if the user is idle for 5 minutes, and if so, it would show them as 'offline' and close down notifications. I was curious if it is possible to detect inactivity even across tabs? (for example if a user switches to another tab to Facebook.com and stays active there, they would be seen as 'active' even though they are not on our webpage specifically).
Is it possible to detect idle time even across tabs?
1.2
0
1
3,773
10,234,885
2012-04-19T18:55:00.000
1
0
0
0
javascript,detect,python-idle
10,235,004
5
false
0
0
if I am on such a thing I use either the HTML5 Visibility API or fallback to blur and focus events observing when the user left the page and then returns... leaving means unfocus the browser window or tab (but still keeping the page open) but since you wanna react on inactivity... hmmm you could start a timeout (of course that would need a global event delegation for many events to stop it if something happens like submit, click, change, mousemove and so on)
3
3
0
I have a script that sends a time-sensitive notification to users when there is a new question directed to them. However, I found that some people leave their computers open and go grab lunch, therefore missing notifications. I'm looking to put together a script that detects if the user is idle for 5 minutes, and if so, it would show them as 'offline' and close down notifications. I was curious if it is possible to detect inactivity even across tabs? (for example if a user switches to another tab to Facebook.com and stays active there, they would be seen as 'active' even though they are not on our webpage specifically).
Is it possible to detect idle time even across tabs?
0.039979
0
1
3,773
10,235,220
2012-04-19T19:19:00.000
2
0
0
1
python,logging,multiprocessing,logrotate
10,238,553
2
false
0
0
As WatchedFileHandler was provided specifically for use with external rotation tools like logrotate, I would suggest that it be used (Option 1). Why do you think you need Option 2? In a multi-process environment where each process writes to its own logs, there shouldn't be any problems. However, processes shouldn't ever share log files.
2
2
0
I am trying to use logrotate to rotate logs for a multi-process python service. Which of the following combination is commonly used (right and safe)? WatchedFileHandler + logrotate with create option OR FileHandler + logrotate with copytruncate option Option-1 seem to be used in openstack nova and glance projects. I have not seen option-2 being used. Will option-2 work as expected?. Are there any drawbacks with these approaches when used for multi-process apps?
Python logging - logrotate options
0.197375
0
0
2,637
10,235,220
2012-04-19T19:19:00.000
0
0
0
1
python,logging,multiprocessing,logrotate
10,235,643
2
false
0
0
I would suggest using Python's own log rotation to get the best integration. The only drawback is that you have an additional place to configure the details.
2
2
0
I am trying to use logrotate to rotate logs for a multi-process python service. Which of the following combination is commonly used (right and safe)? WatchedFileHandler + logrotate with create option OR FileHandler + logrotate with copytruncate option Option-1 seem to be used in openstack nova and glance projects. I have not seen option-2 being used. Will option-2 work as expected?. Are there any drawbacks with these approaches when used for multi-process apps?
Python logging - logrotate options
0
0
0
2,637
10,235,579
2012-04-19T19:42:00.000
0
0
0
0
python,django,beautifulsoup
10,235,640
2
false
1
0
Try copying and pasting that URL into your browser. I get an access key error; fix that and your problem is solved.
1
1
0
Beautiful Soup works in the Python shell using Django. I can also successfully import from bs4 import BeautifulSoup into views.py, but when I call something like soup = BeautifulSoup(xml), I get a 502 Bad Gateway error. I talked to my host, and they could not find the problem. Any ideas? Note the xml is xml = urllib2.urlopen("http://isbndb.com/api/books.xml?access_key=000000&results=details&index1=isbn&value1=0000").read(), but it works in the Python shell (within myproject folder), so I wouldn't think that's the problem.
502 Bad Gateway using Beautiful Soup, Python/Django
0
0
0
1,024
10,236,321
2012-04-19T20:35:00.000
4
1
0
0
python,point-of-sale,prototyping
10,236,867
2
false
1
0
Python is a very quick and productive language to develop in, so that would be a good choice, IMO. Personally I find it the most pleasant language to develop in. But I think a POS system is a terrible first programming project. A proper POS system covers too many aspects like security, authentication, data storage, client-server. Each of those has its own gotcha's and significant learning curve. If you want to go through with it nonetheless, chop the project up into manageable pieces that can be built and tested separately. You could start by writing a simple program that accepts text commands from the console and stores the transactions in e.g. a text file or in a pickled Python dictionary. This would be the start of the server. Later you can add a web or GUI front-end, or have the server store transactions in a database.
1
3
0
I am considering of prototyping a web based point-of-sale system. I don't have programming skills but I'm thinking of using this project in order to learn. I would like to ask you the following two questions: Do you think the above task is achievable within the period of 6 months (for building a rough prototype of the basic functions of a POS)? If yes, which programming language would you recommend me and why? (I was thinking of Python) Your advice is greatly appreciated!
Creating a web based point of sale system
0.379949
0
0
9,646
10,238,473
2012-04-19T23:53:00.000
0
1
1
0
python,pylint
44,339,590
6
false
0
0
My use case is to run pylint *.py to process all files in a directory, except that I want to skip one particular file. Adding # pylint: skip-file caused Pylint to fail with I: 8, 0: Ignoring entire file (file-ignored). Adding # pylint: disable=file-ignored does not fix that. Presumably, it's a global error rather than a file-specific one. The solution was to include --disable=file-ignored in the Pylint command options. It took way too long to figure this out; there shouldn't be a file-ignored error when you explicitly ignore a file.
2
116
0
We are using Pylint within our build system. We have a Python package within our code base that has throwaway code, and I'd like to disable all warnings for a module temporarily so I can stop bugging the other devs with these superfluous messages. Is there an easy way to pylint: disable all warnings for a module?
Disable all Pylint warnings for a file
0
0
0
88,564
10,238,473
2012-04-19T23:53:00.000
7
1
1
0
python,pylint
10,276,255
6
false
0
0
Another option is to use the --ignore command line option to skip analysis for some files.
2
116
0
We are using Pylint within our build system. We have a Python package within our code base that has throwaway code, and I'd like to disable all warnings for a module temporarily so I can stop bugging the other devs with these superfluous messages. Is there an easy way to pylint: disable all warnings for a module?
Disable all Pylint warnings for a file
1
0
0
88,564
10,239,073
2012-04-20T01:32:00.000
4
0
1
0
python,django
10,239,569
1
true
1
0
It's not a problem unless you find yourself writing exactly the same code on model after model. At that point you should consider writing a template tag that takes the model as a parameter instead.
1
6
0
I would like to know what would be the best practice. I have been using the @property decorator a lot because it allows me to avoid creating custom context variables when I want to display something related to a model instance on a template. I feel like my models are too big. Is this ok?
Django models: when should I use the @property decorator for attributes?
1.2
0
0
1,584
10,241,279
2012-04-20T06:27:00.000
0
0
1
1
python,emacs,interpreter
15,099,767
8
false
0
0
In emacs 24.2 there is python-switch-to-python
2
32
0
I just downloaded GNU emacs23.4, and I already have python3.2 installed in Windows7. I have been using Python IDLE to edit python files. The problem is that I can edit python files with Emacs but I do not know how to run python interpreter in Emacs. When i click on "switch to interpreter", then it says "Searching for program: no such file or directory, python" Someone says i need to make some change on .emacs file, but i do not know where to look for. And I am very unexperienced and just started to learn programming. I am not familiar with commonly used terminologies. I have been searching for solutions but most of the articles i find on the Internet only confuse me. so the questions are: how do i run python interpreter in Emacs? are there different kind of python interpreter? if so, why do they have different interpreters for one language?
How do I run a python interpreter in Emacs?
0
0
0
37,056
10,241,279
2012-04-20T06:27:00.000
14
0
1
1
python,emacs,interpreter
20,375,113
8
false
0
0
C-c C-z can do this. It is the key-binding for the command python-switch-to-python
2
32
0
I just downloaded GNU emacs23.4, and I already have python3.2 installed in Windows7. I have been using Python IDLE to edit python files. The problem is that I can edit python files with Emacs but I do not know how to run python interpreter in Emacs. When i click on "switch to interpreter", then it says "Searching for program: no such file or directory, python" Someone says i need to make some change on .emacs file, but i do not know where to look for. And I am very unexperienced and just started to learn programming. I am not familiar with commonly used terminologies. I have been searching for solutions but most of the articles i find on the Internet only confuse me. so the questions are: how do i run python interpreter in Emacs? are there different kind of python interpreter? if so, why do they have different interpreters for one language?
How do I run a python interpreter in Emacs?
1
0
0
37,056
10,241,950
2012-04-20T07:23:00.000
0
0
0
0
php,python,temporary-files
10,266,536
3
true
1
0
I don't know why I didn't think of it, but I was on an IRC for Python, discussing a completely unrelated issue, and someone asked why I didn't just serve the file. Exactly! I never needed to save the file, just to send it back to the user with the correct header. Problem solved!
1
3
0
I need to set up a page that will let the user upload a file, modify the file with a script, and then serve the file back to the user. I have the uploading and modifying parts down, but I don't know where to put the file. They are going to be in the area of 1 or 2mb, and I have very little space on my webhosting plan, so I want to get rid of the files as soon as possible. There's no reason for the files to exist any longer than after the users are given the option to download by their browser upon being redirected. Is the only way to this with a cron job that checks the creation time of the files and deletes them if they're a certain age? I'm working with python and PHP. edit: First the file is uploaded. Then the location of the file is sent back to the user. The javascript on the page redirects to the path of the file. The browser opens save file dialog, and they choose to save the file or cancel. If they cancel, I want to delete the file immediately. If they choose to save the file, I want to delete the file once their download has completed.
Store file for duration of time on webpage
1.2
0
1
136
10,242,525
2012-04-20T08:10:00.000
1
0
1
0
python,dictionary,parallel-processing,multiprocessing,large-data
10,248,052
2
false
0
0
I hit a similar issue: parallelizing calculations on a big dataset. As you mentioned multiprocessing.Pool.map pickles the arguments. What I did was to implement my own fork() wrapper that only pickles the return values back to the parent process, hence avoiding pickling the arguments. And a parallel map() on top of the wrapper.
1
2
1
Is it efficient to calculate many results in parallel with multiprocessing.Pool.map() in a situation where each input value is large (say 500 MB), but where input values general contain the same large object? I am afraid that the way multiprocessing works is by sending a pickled version of each input value to each worker process in the pool. If no optimization is performed, this would mean sending a lot of data for each input value in map(). Is this the case? I quickly had a look at the multiprocessing code but did not find anything obvious. More generally, what simple parallelization strategy would you recommend so as to do a map() on say 10,000 values, each of them being a tuple (vector, very_large_matrix), where the vectors are always different, but where there are say only 5 different very large matrices? PS: the big input matrices actually appear "progressively": 2,000 vectors are first sent along with the first matrix, then 2,000 vectors are sent with the second matrix, etc.
When to and when not to use map() with multiprocessing.Pool, in Python? case of big input values
0.099668
0
0
2,008
10,243,310
2012-04-20T09:10:00.000
1
0
0
0
php,python,django,wordpress,heroku
10,243,597
1
true
1
0
no, application type is determined at slug compilation time when the application is pushed to Heroku. Not sure if you could do anything with a custom build pack but I would have thought so.
1
1
0
Is it possible to run some php app (e.g. wordpress) together with django within one heroku instance, so that the part of app's urls would be served by php and the rest by django?
PHP together with django in heroku instance
1.2
0
0
252
10,244,713
2012-04-20T10:44:00.000
0
0
0
1
c++,python,objective-c,plugins,cross-platform
10,245,373
2
false
0
1
The simplest way to share the cross-platform Python component of your application would probably be to implement it as a command-line program, and then invoke it using the relevant system calls in each of the front-ends. It's not the most robust way, but it could be sufficient. If you want plugins to just be a file containing Python code, I would recommend that they at least conform to a convention, e.g. by extending a class, and then have your code load them into the Python runtime using "import plugin_name". This would be better than having the plugins exist as separate programs because you would be able to access the output as Python types, rather than needing to parse text from standard input.
1
0
0
I am writing an application which should be able to run on Linux, Mac OS X, Windows and BSD (not necessarily as a single executable, so it doesn't have to be Java) and be extensible using simple plugins. The way I want my plugins to be implemented is as a simple Python program which must implement a certain function and simply return a dictionary to the main program. Plugin installation should just be a matter of copying the plugin script file into the ./plugins directory relative to the main executable. The main program should be a stand-alone executable with shared code amongst all of the above platforms, but with platform specific front-ends (so the Linux and BSD versions would just be CLI tools, the Windows version have C++ and MFC front-end, and the Mac OS X version would have a Objecive-C and Cocoa front-end). So I guess it's really two questions: What's the simplest way to share common controller code between multiple front ends from: a. Objective-C on a Mac? b. C++ on Windows? c. C/Python from Linux/BSD? What's the simplest way to implement plugins from my common controller to execute custom plugins?
Simplest way to write cross-platform application with Python plugin extensibility?
0
0
0
1,296
10,246,539
2012-04-20T12:47:00.000
2
0
0
1
python,asynchronous,tornado
10,246,669
1
true
0
0
Yes, as I understand your question, that is a normal use-case for Tornado. If all requests to your Tornado server would make requests to myapi.com, and myapi.com is blocking, then yes, myapi.com would still be the bottleneck. However, if only some requests have to be handled by myapi.com, then Tornado would still be a win, as it can keep handling such requests while waiting for responses for the requests to myapi.com. But regardless, if myapi.com can't handle the load, then putting a Tornado server in front of it won't magically fix that. The difference is that your Tornado server will still be able to respond to requests even when myapi.com is busy.
1
2
0
I have just begun to look at tornado and asynchronous web servers. In many examples for tornado, longer requests are handled by something like: make a call to tornado webserver tornado makes async web call to an api let tornado keep taking requests while callback waits to be called handle response in callback. server to user. So for hypothetical purposes say users are making a request to tornado server at /retrive. /retrieve will make a request to an internal api myapi.com/retrieve_posts_for_user_id/ or w/e. the api request could take a second to run while getting requests, then when it finally returns tornado servers up the response. First of all is this flow the 'normal' way to use tornado? Many of the code examples online would suggest so. Secondly, (this is where my mind is starting to get boggled) assuming that the above flow is the standard flow, should myapi.com be asyncronous? If its not async and the requests can take seconds apiece wouldn't it create the same bottleneck a blocking server would? Perhaps an example of a normal use case for tornado or any async would help to shed some light on this issue? Thank you.
Tornado/Async Webserver theory, how to handle longer running operations to utilize the async server
1.2
0
0
652
10,247,264
2012-04-20T13:31:00.000
12
0
1
0
python,naming,nomenclature
10,247,378
3
false
0
0
I think site is used to mean the same thing as local, as in /usr/local/* - it's those elements that are installed locally/for this site, as opposed to those that are provided by the system.
2
13
0
I've always been a bit curious about the rationale of the naming of site-packages. What does site mean in this context? I doubt it means 'website', and I've never heard 'site' used in relation to the installation location, or the context of the machine. Any ideas?
What does 'site' in 'site-packages' actually mean?
1
0
0
501
10,247,264
2012-04-20T13:31:00.000
5
0
1
0
python,naming,nomenclature
10,247,716
3
false
0
0
I have always understood this as short for on-site - oposite to remote. Probably because those are the packages that are on your machine. That's just my guess, though :)
2
13
0
I've always been a bit curious about the rationale of the naming of site-packages. What does site mean in this context? I doubt it means 'website', and I've never heard 'site' used in relation to the installation location, or the context of the machine. Any ideas?
What does 'site' in 'site-packages' actually mean?
0.321513
0
0
501
10,248,880
2012-04-20T15:13:00.000
0
0
1
0
python,opencv
59,521,987
4
false
0
0
In terminal write: for python 2.X python2 -c 'import cv2; print cv2.__version__' for python 3.X python3 -c 'import cv2; print(cv2.__version__)'
1
20
0
I want to write to short code snippet in python, to determine which version of OpenCV has been installed in my System. How do i do it ? Thank you.
Determine which version of OpenCV
0
0
0
31,954
10,249,121
2012-04-20T15:31:00.000
0
0
0
0
python
10,249,180
3
false
0
0
Get the functional module from pypi. It has a compose function to compose two callables. With that, you can chain functions together. Both that module, and functool provide a partial function, for partial-application. You can use the composed functions in a generator expression just like any other.
1
3
0
here is the problem: 1) suppose that I have some measure data (like 1Msample read from my electronics) and I need to process them by a processing chain. 2) this processing chain consists of different operations, which can be swapped/omitted/have different parameters. A typical example would be to take this data, first pass them via a lookup table, then do exponential fit, then multiply by some calibration factors 3) now, as I do not know what algorithm the the best, I'd like to evaluate at each stage best possible implementation (as an example, the LUTs can be produced by 5 ways and I want to see which one is the best) 4) i'd like to daisychain those functions such, that I would construct a 'class' containing top-level algorithm and owning (i.e. pointing) to child class, containing lower-level algorithm. I was thinking to use double-linked-list and generate sequence like: myCaptureClass.addDataTreatment(pmCalibrationFactor(opt, pmExponentialFit (opt, pmLUT (opt)))) where myCaptureClass is the class responsible for datataking and it should as well (after the data being taken) trigger the top-level data processing module (pm). This processing would first go deep into the bottom-child (lut), treat data there, then middle (expofit), then top (califactors) and return the data to the capture, which would return the data to the requestor. Now this has several issues: 1) everywhere on the net is said that in python one should not use double-linked-lists 2) this seems to me highly inefficient because the data vectors are huge, hence i would prefer solution using generator function, but i'm not sure how to provide the 'plugin-like' mechanism. could someone give me a hint how to solve this using 'plugin-style' and generator so I do not need to process vector of X megabytes of data and process them 'on-request' as is correct when using generator function? thanks a lot david An addendum to the problem: it seems that I did not express myself exactly. Hence: the data are generated by an external HW card plugged into VME crate. They are 'fetched' in a single block transfer to the python tuple, which is stored in myCaptureClass. The set of operation to be applied is in fact on a stream data, represented by this tuple. Even exponential fit is stream operation (it is a set of variable state filters applied on each sample). The parameter 'opt' i've mistakenly shown was to express, that each of those data processing classes has some configuration data which come with, and modify behaviour of the method used to operate on data. The goal is to introduce into myCaptureClass a daisychained class (rather than function), which - when user asks for data - us used to process 'raw' data into final form. In order to 'save' memory resources i thought it might be a good idea to use generator function to provide the data. from this perspective it seems that the closest match to what i want to do is shown in code of bukzor. I'd prefer to have a class implementation instead of function, but i guess this is just a cosmetic stuff of implementing call operator in particular class, which realizes the data operation....
how to implement 'daisychaining' of pluggable function in python?
0
0
0
987
10,249,240
2012-04-20T15:38:00.000
1
1
1
0
python,character-encoding
10,250,521
1
true
0
0
If it is None, simply output your data as utf-8, and document it. If it happens that there are use cases for other encodings, make that an option through the command line or other means.
1
2
0
I am trying to handle the different encodings in a Python script the more user-friendly and auto-magic way possible (there are APIs for utf8). It is a cross-platform console script. For printing to stdout I use sys.stdout.encoding and it seems to do the right thing almost always when printing to the console. However when stdout is piped it becomes None. So in that case I assume I am piping to a file and use locale.getpreferredencoding() but: I am not sure this is the right encoding for printing to a file, but it works quite cross-platform. That doesn't work when piping to a program |. I don't know how to detect that this is the case neither if there is a standard or an expected behavior for encoding in that case.
What should I do when sys.stdout.encoding is None?
1.2
0
0
643
10,250,353
2012-04-20T16:55:00.000
1
0
0
1
java,python,windows,stdin
10,251,723
1
true
1
0
Have the java app read from a named pipe. A named pipe allows multiple clients to write to it, and are language-agnostic.
1
0
0
I need to send text to a java app's stdin that is started independently from Python. I have been using pywin32 sendkeys up to this point, but there are some inconsistencies with the output that are making me look for other solutions. I am aware of subprocess, but it looks like that can only be used to interact with a child process that was started by Python, not one that is started independently. Socket is not an option for me because Windows does not allow multiple connections to the same port.
Python: possible to send text to a java app's stdin that is already running?
1.2
0
0
159
10,250,437
2012-04-20T17:00:00.000
1
0
0
0
java,python
10,251,394
1
true
1
0
Ask the company that makes the software if they have an SDK or documentation on their API. Even if they have one, if you already don't like the application, this may not be much use to you. If the main purpose of the application is to report on the contents of a database, there are plenty of libraries in python for reading/writing to databases. SQLAlchemy/Storm and PyQt could probably do what you want.
1
0
0
I have one proprietary software my office uses for database access and reporting which nobody likes in my office. I am thinking of building a python/Java application with a simple interface which does the task of communicating with the propriety software. My problem is: Since the software is proprietary, there is no known API of any sort I am aware of such that I can interface. Is there a way around to get through this or is it mandatory to have API to access the software? I am doing this in windows XP platform.
Creating interface with the software without API-Possibilities
1.2
0
0
266
10,252,304
2012-04-20T19:22:00.000
1
0
1
1
python,gcc,cygwin,pypy
10,252,762
3
false
0
0
Windows needs the ".exe" extension to know that it's executable. You'll need to modify the build to look for Windows and use the .exe extension.
1
2
0
I'm trying to compile PyPy on cygwin, and the compilation stops when python tries to open the file "externmod", which was just compiled with gcc. The problem with gcc on cygwin is that it automatically appends a '.exe' to whatever you're compiling, so even though gcc is called as gcc -shared -Wl,--enable-auto-image-base -pthread -o /tmp/usession-release-1.8/shared_cache/externmod, the output file ends up being externmod.exe regardless. So python tries to open /tmp/usession-release-1.8/shared_cache/externmod and can't find it--thus the compilation stops. Anyone know how to solve this, short of recompiling gcc? I don't want to do that.
Compiling PyPy on cygwin
0.066568
0
0
1,101
10,253,855
2012-04-20T21:34:00.000
4
0
1
0
python,python-3.x,copy,deep-copy
10,254,186
2
true
0
0
Is it really necessary to use the copy module for copying instances of this class? I would argue that instead of overriding __copy__ or __deepcopy__ you should create a copy method for your class that returns a new object using the copy semantics you defined. If for some consistency reason you do need to use the copy module, then in my opinion __deepcopy__ is more appropriate. If it is a defined behavior of the class that all instances share one of the containers, then it is reasonable to assume that an implementation of __deepcopy__ would respect that.
1
6
0
My class represents states of various systems. Each instance has two attributes: one is a container shared between all the states of the same system, and the other is a container that is unique to each instance. A copy of a state should reuse the "shared" attribute, but create a deep copy of the "unique" attribute. This is really the only copy semantics that makes sense (it's natural that the copy of a state is a state of the same system). I want to create the least surprise for people who read and maintain my code. Should I override __deepcopy__ or __copy__ for my purposes?
copy vs deepcopy: semantics
1.2
0
0
764
10,253,898
2012-04-20T21:37:00.000
3
1
0
0
python,cgi
10,254,010
2
true
0
0
there are a couple of options, use the logging module as directed, you can tail the server's error log, and you can enable cgitb with import cgitb; cgitb.enable() Depending on exactly where the error occurs, the error will show up in different places, so checking all three, and using print statements and exception blocks helps to debug your code. With file uploads, I've found I have to explicitly state enctype="multipart/form-data" in the form tag or it breaks, often quietly.
1
0
0
I'm new to cgi and python, so I've been making quite a few mistakes. The problem is that if something goes wrong with the script, I just get a 500 error on the webpage. The only way I can see what caused the error is by executing the page via ssh, but the page involves file uploads, so I can't test that part. Is there a way I can output Python errors to a file?
Logging python errors on website?
1.2
0
1
2,081
10,254,466
2012-04-20T22:42:00.000
6
0
0
0
python,django,django-templates
10,255,173
1
true
1
0
Even if this might be possible to achieve in the template, I (and probably many other people) would advise against it. To achieve this, you basically need to find out whether there are any objects in the database matching some criteria. That is certainly not something that belongs into a template. Templates are intended to be used to define how stuff is displayed. The task you're solving is determining what stuff to display. This definitely belongs in a view and not a template. If you want to avoid placing it in a view just because you want the information to appear on each page, regardless of the view, consider using a context processor which would add the required information to your template context automatically, or writing a template tag that would solve this for you.
1
1
0
I have the following code in my template: {% for req in user.requests_made_set.all %} {% if not req.is_published %} {{ req }} {% endif %} {% empty %} No requests {% endfor %} If there are some requests but none has the is_published = True then how could I output a message (like "No requests") ?? I'd only like to use Django templates and not do it in my view! Thanks
Django template check for empty when I have an if inside a for
1.2
0
0
3,317
10,255,185
2012-04-21T00:44:00.000
2
0
0
0
python,excel,web-scraping
10,255,232
2
false
0
0
if you don't want to introduce a full excel library, you can write an HTML table or CSV and Excel will happily import those. The downside with this is that you're limited to one worksheet and no formulaes.
1
2
0
I would like to know how I would have a python web scrape dump all of it's results into excel. It's not that I don't know how to webscrape, it's just I do not know how to scrape into excel.
How to scrape in python into excel
0.197375
0
1
4,830
10,255,319
2012-04-21T01:07:00.000
0
0
0
1
python,networking,arp,scapy,spoof
10,255,376
1
false
0
0
The strange thing I see here that how the ARP Reply bounced back to VM(1) although it uses a spoofed MAC address.. Well, try to check on the ARP table on VM (2) and see which MAC record it holds for VM (1); probably you'll find the legitimate MAC address cached due to some communications before you spoof the MAC address.
1
3
0
I am programming with Python and his partner Scapy. I am facing a situation that i dont know if it is a normal behavior from ARP Protocol or some another problem. I have this scenario: 1- A vm machine (1) sending an "ARP Request" to another vm machine (2) with Spoofed Source MAC Address field (generated with Scapy). 2 - The vm machine (2) receives that "ARP Request" with the Source MAC Address field Spoofed and RESPONDS that with an "ARP Reply". The strange part is that the vm machine (1) receives that. Notes: I have confirmed with Wireshark that the first packet (ARP Request) gets on the vm machine (2) with the Source MAC Address Field REALLY spoofed. And the promiscous mode on networks interfaces are disabled, so, the vm machines only receive packets that are REALLY destined to their interfaces. So, my questions: a) Is it the normal behavior from ARP Protocol? b) Because vm machine (1) has another MAC Address configured on your interface (the real one), how the response packet sent from vm machine (2) with another MAC Address on the Destination field (that is spoofed, so, not even exists on the network) arrives to vm machine (1) and is effectively processed by vm machine (1) like a valid "ARP Reply"??
Behavior of Spoof MAC Address communication
0
0
0
1,699
10,258,703
2012-04-21T12:01:00.000
2
0
1
0
android,python
10,258,955
2
true
1
1
Your users have to install SL4A and the language plugin (python?) on their phones, this is not a built-in functionality. Since the source code is available, it's possible to create combined application, which includes your scripts and SL4A/python code, but in my opinion this defies the purpose of scripting in the first place.
1
6
0
In order to develop an Android app using Python, I need to install Python for Android and SL4A on my computer to be used with the Android emulator. My question is, when I distribute this app to actual users/phones, do the phones need to get Python for Android and SL4A explicitly? Or is the supporting infrastructure built into Android devices? Or is there a way to package the Python application where the users do not have to get SL4A and Python for Android in order to run the application?
Running a Python app on real Android phone
1.2
0
0
1,128
10,259,148
2012-04-21T13:02:00.000
3
0
0
1
python,ide,geany
10,625,293
1
true
0
0
To solve that problem I added additional parameters to terminal command that geany runs. In Geany go to preferences (Edit->Preferences). Open Tools tab. There is an input field named Terminal where you can specify terminal program to use. I changed that to "gnome-terminal --maximize" to open terminal maximized. For Gnome-Terminal you can find more window options running "gnome-terminal --help-window-options" from terminal.
1
3
0
I'm using Geany 0.18 for python developing and am in general really satisfied, but there is one little thing, that's still bugging me: I usually use the F5 (Build-->Execute) option to test my scripts, the appearing window is rather small, and if my script prints lines which are too long they are hard to read. I would like to change the default-window size of the little one popping up if I hit F5, but I haven't found anything to accomplish this. Is this possible at all ? Thanks Mischa
Changing window size of Geany's execute (F5) option
1.2
0
0
1,116
10,260,925
2012-04-21T16:36:00.000
2
0
0
1
python,celery
43,633,216
2
false
1
0
The way I deployed it is like this: clone your django project on a heroku instance (this will run the frontend) add RabitMQ as an add on and configure it clone your django project into another heroku instance (call it like worker) where you will run the celery tasks
2
58
0
I am new to celery.I know how to install and run one server but I need to distribute the task to multiple machines. My project uses celery to assign user requests passing to a web framework to different machines and then returns the result. I read the documentation but there it doesn't mention how to set up multiple machines. What am I missing?
How to set up celery workers on separate machines?
0.197375
0
0
26,305
10,260,925
2012-04-21T16:36:00.000
60
0
0
1
python,celery
10,261,277
2
true
1
0
My understanding is that your app will push requests into a queueing system (e.g. rabbitMQ) and then you can start any number of workers on different machines (with access to the same code as the app which submitted the task). They will pick out tasks from the message queue and then get to work on them. Once they're done, they will update the tombstone database. The upshot of this is that you don't have to do anything special to start multiple workers. Just start them on separate identical (same source tree) machines. The server which has the message queue need not be the same as the one with the workers and needn't be the same as the machines which submit jobs. You just need to put the location of the message queue in your celeryconfig.py and all the workers on all the machines can pick up jobs from the queue to perform tasks.
2
58
0
I am new to celery.I know how to install and run one server but I need to distribute the task to multiple machines. My project uses celery to assign user requests passing to a web framework to different machines and then returns the result. I read the documentation but there it doesn't mention how to set up multiple machines. What am I missing?
How to set up celery workers on separate machines?
1.2
0
0
26,305
10,262,114
2012-04-21T19:10:00.000
7
1
0
1
python,scripting,programming-languages,lua
10,262,395
5
false
0
0
Lua strings are encoding-agnostic. So, yes, you can write unicode strings in Lua scripts. If you need pattern matching, then the standard Lua string library does not support unicode classes. But plain substring search works.
1
2
0
I need to script my app (not a game) and I have a problem, choosing a script lang for this. Lua looks fine (actually, it is ideal for my task), but it has problems with unicode strings, which will be used. Also, I thought about Python, but I don't like It's syntax, and it's Dll is too big for me ( about 2.5 Mib). Python and other such langs have too much functions, battaries and modules which i do not need (e.g. I/O functions) - script just need to implement logic, all other will do my app. So, I'd like to know is there a scripting lang, which satisfies this conditions: unicode strings I can import C++ functions and then call them from script Can be embedded to app (no dll's) without any problems Reinventing the wheel is not a good idea, so I don't want to develop my own lang. Or there is a way to write unicode strings in Lua's source? Like in C++ L"Unicode string"
Choosing Scripting lang
1
0
0
492
10,264,905
2012-04-22T03:10:00.000
2
0
0
0
python,flask
10,269,311
1
false
1
0
I figured it's probably not possible. It's not possible for the server to receive the entire request as it has to terminate the connection once the max_content_length threshold has been passed, discarding any other form data that would have been sent after the file upload. The server resets the connection with a HTTP 413 status code. While it appears it's possible to register a function to handle HTTP 413 errors (and presumably to return a custom error page), this doesn't work in Flask. I assume this is a bug.
1
2
0
I've read through the docs and Googled my problem, but I don't seem to be able to figure out a way to handle errors in Flask without terminating the request and displaying an error page. The error I want to handle is werkzeug.exceptions.RequestEntityTooLarge which is raised when a file upload exceeds the specified limit. Ideally I want to be able to add an element to the flask.request.files dictionary indicating that the uploaded file exceeded the maximum upload size. The error could then be presented inline with the original form so the user can try again. Is this even possible in Flask?
Capturing errors in Flask but continuing with the request as normal
0.379949
0
0
327
10,265,351
2012-04-22T04:56:00.000
0
1
1
0
python
10,265,367
2
false
0
0
It comes with the book "Python Scripting for Computational Science".
2
0
0
I need the python moduel py4cs, but I cannot find it anywhere, it is not on pypi or anywhere else. Please Help. Thanks!
Where to find a python module, py4cs?
0
0
0
186
10,265,351
2012-04-22T04:56:00.000
1
1
1
0
python
23,199,828
2
false
0
0
It is a set of tools useful for scientific programming in Python. Initially, it was distributed as py4cs only with purchase of the book by Hans Petter Langtangen. It is now called scitools and is widely available.
2
0
0
I need the python moduel py4cs, but I cannot find it anywhere, it is not on pypi or anywhere else. Please Help. Thanks!
Where to find a python module, py4cs?
0.099668
0
0
186
10,265,506
2012-04-22T05:32:00.000
0
0
0
1
python,twisted
10,267,334
1
false
0
0
You might want to consider running an established load-balancing reverse proxy such as HAProxy or nginx, since it will be the weak point of your system. If you have a bug in your reverse proxy/load balancer, everything goes down. You could also handle SSL at the proxy so your twisted application servers don't need handle it.
1
0
0
I'm looking for a way implement a reverseProxy to copies of (Twisted) server processes. I'm think of a setup where the business logic is run in copies to allow for easy maintenance and upgrade, and stores shared data in a database and perhaps memcached. I saw the reverseProxy class in twisted.web, but I don't think this is what I'm looking for for non-HTTP. First off, is this a good design in general and/or is there a more "twisted" way to do it?
TCP reverse proxy to copies of Twisted business logic processes
0
0
0
382
10,267,841
2012-04-22T12:14:00.000
2
0
1
0
python,for-loop,arraylist,operators,boolean
10,267,873
6
false
0
0
As you wrote it, python evaluates ('.png' or '.jpg' or 'jpeg'), and compares i[-4:] to the result. What you probably want is what @ThiefMaster suggests: the in operator.
1
1
0
I am trying to populate a list called images with files that have the extensions '.png', '.jpg' or 'jpeg' in a one line for loop. I tried this by using the logical or operator but that only resulted in an empty list. images = [i for i in os.listdir('.') if i[-4:] == ('.png' or '.jpg' or 'jpeg')] How do I check to see if '.png', '.jpg' or 'jpeg' are the last 4 characters of the file while keeping it all in a one line for loop?
Python logical or operator acting strange
0.066568
0
0
335
10,268,189
2012-04-22T13:09:00.000
0
1
1
0
python,unit-testing,nose,distribute,python-2to3
10,294,908
1
true
0
0
OK, I did some more lookup and I found that at least in nose there is a custom script that adds this command. So I will probably have to copy this idea if I want to have tests for py3k.
1
0
0
When I was reading examples for testing a package in multiple pythons with tox I found about a command "build_tests" that would put (2to3'd) test files in build/ directory. I could also google it in some projects' tox.ini files and some gentoo ebuilds, but I still don't know which package installs this command. I have python 3.2, last nosetests and last distribute, but "python setup.py build_tests" still gives error. So what do I have to install to get this command?
Where to find build_tests command?
1.2
0
0
82
10,269,245
2012-04-22T15:28:00.000
0
0
0
1
python,eclipse,pydev
10,273,751
1
true
0
0
I got it. When I was creating a file, I needed to specify the .py extension. After doing this, the file ran.
1
1
0
This is my first time using Eclipse, so I think it must be some newbie configuration error. However, I can not sort it out, so I hope one of you might be able to help me. This is what I did: Installed Python 2.7 Installed EasyEclipse for Python 1.3.1 Went to Window>Preferences>Pydev>Interpreter-Python and selected C:\python27\python.exe Created a new project (when I had to select project type, there was only python 2.3, 2.4, and 2.5, so I selected 2.5, even though I am running 2.7) Created a file in that project with a simple helloworld. Clicked the "Run" play button. When I do this, I get the error "The selection cannot be launched, and there are no recent launches." As I said, I get the feeling this is just some configuration issue. In particular, could it be something about my "run configuration"? I see this as a dialog box, but I really don't know what I am supposed to be doing in it. Your help is greatly appreciated. Thank you.
Trying to Run a Python script using EasyEclipse for Python, get error "The selection cannot be launched, and there are no recent launches."
1.2
0
0
2,868
10,270,331
2012-04-22T17:35:00.000
-1
0
1
0
python,html,regex,markdown,markup
10,270,412
2
false
0
0
Regular expressions, of course! If still haven't done so, learn it. After you are done, you will find it hard to imagine how you got along without it. The samples you show are simple with regular expressions. For example, an asterisk, then a space then a word is expressed as: \*\s\w+ Nothing else but regular expressions.
1
1
0
This question may have been asked in a different way, if so please point it to me. I just couldn't find it among my search results. I would like to parse text for mark-ups, like those here on SO. eg. * some string for bullet list eg. *some string* for italic text eg. &some string& for a URL eg. &some string&specific url& for URL different from string etc. I can think of two ways to go about processing a string to find out special mark-up sequences: a. I could proceed in a character-centric way, i.e. parsing the string looking for sequences 1, then 2 etc. That however seems to be inefficient as it would have to parse the string multiple times. b. It seems better to process the string character by character and keep a memory of special characters and their position. If the memory matches a special sequence as above, then the special characters are replaced by HTML in the string. I'm not really sure whether that's a better idea however, nor am I sure as to how one should implement it. What is the best way to go about this? How about Regular Expressions? Does it follow pattern a or b? Is there a third option? P.S. I am using Python. Python example most appreciated.
What is the most efficient way to trace markups in a string?
-0.099668
0
0
102
10,273,186
2012-04-22T23:49:00.000
6
0
1
0
python,copy
10,273,201
2
true
0
0
The right is evaluated first, placed into a temporary variable, and x is re-assigned to the temp variable. You never see it, of course.
1
4
0
It copies a list right? but in the code I'm looking at its x = x[:] which I don't understand. How can both copies be called the same thing?
How does [:] work in python?
1.2
0
0
388
10,274,231
2012-04-23T02:45:00.000
12
0
1
1
python,listdir
10,274,338
1
true
0
0
I personally find the division between os and os.path to be a little inconsistent. According to the documentation, os.path should just be an alias to a module that works with paths for a particular platform (i.e., on OS X, Linux, and BSD you'll get posixpath, on Windows or ancient Macs you'll get something else). >>> import os >>> help(os) Help on module os: NAME os - OS routines for Mac, NT, or Posix depending on what system we're on. ... >>> help(os.path) Help on module posixpath: NAME posixpath - Common operations on Posix pathnames. The listdir function doesn't operate on the path itself, instead it operates on the directory identified by the path. Most of the functions in os.path operate on the actual path and not on the filesystem. This means that many functions in os.path are string manipulation functions, and most functions in os are IO functions / syscalls. Examples: os.path.join, os.path.dirname, os.path.splitext, are just string manipulation functions. os.listdir, os.getcwd, os.remove, os.stat are all syscalls, and actually touch the filesystem. Counterexamples: os.path has exists, getmtime, islink, and others which are basically wrappers around os.stat, and touch the filesystem. I consider them miscategorized, but others may disagree. Fun fact of the day: You won't find the modules in the top level of the library documentation, but you can actually import the version of os.path for any platform without having to actually run on that platform. This is documented in the documentation for os.path, However, you can also import and use the individual modules if you want to manipulate a path that is always in one of the different formats. They all have the same interface: posixpath for UNIX-style paths ntpath for Windows paths macpath for old-style MacOS paths os2emxpath for OS/2 EMX paths You can't do the same thing with os, it wouldn't make any sense.
1
2
0
os.path module seems to be the default module for all path related functions. Yet, the listdir() function is part of the os module and not os.path module, even though it accepts a path as its input. Why has this design decision been made ?
Why is the listdir() function part of os module and not os.path?
1.2
0
0
370
10,279,943
2012-04-23T11:47:00.000
0
0
1
0
python-2.7
10,595,746
1
false
0
0
Start with the example from the python library documentation for os.walk it is close to what you need. Test the directorynames and filenames with os.path.islink to seperate the dirs/files from the links. Keep three counters in the local environment, one for each of the things you want to count.
1
0
0
I need the Python code to recursively search through a given path and return the number of files, folders and symbolic links within the location passed in? It should just do the search of the directory once and then increment the value of num of files, num of dirs, num of symbolic links as it is executed. It shouldn't be 3 separate searches of the directory tree for each value. Help really appreciated.
File, folder and symbolic link recursive count using Python
0
0
0
607
10,282,132
2012-04-23T14:05:00.000
4
1
1
0
python,perl,bash,sed,awk
10,282,359
3
false
0
0
grep '\$NT\$'filename If there might be other occurrences of $NT$ outside the field you're looking for, you could be more specific - this will find only lines that have it in the second colon-delimited field: awk -F: '$2 ~ /\$NT\$/'filename
1
0
0
I am attempting to write a script that will pull out NTLM hashes from a text file that contains about 500,000 lines of data. Not all accounts contain hashes and I only need the ones that do contain hashes. Here is a sample of what the data looks like: Mango Chango A (a):$NT$547e2494658ca345d3847c36cf1fsef8::: There are thousands of other lines in the file, but that particular line is what I need taken out of the file. There are about 100 lines that apply to that and I do not want to manually go through the entire file searching for that. Is there an easy script or something I can run in Linux to pull lines that follow that pattern out of the file? Thank you!
Script to pull hashes out of large text file
0.26052
0
0
575
10,282,347
2012-04-23T14:17:00.000
1
0
0
0
python,django,desktop-application,web-frameworks
10,285,038
3
false
1
0
This might not fit with how your users use your application but one option would be to make a Linux virtual machine (Virtualbox supports most common operating systems as hosts) and distribute that instead. This would give you a single target to develop against and, as a bonus if you looked into the update mechanism of your chosen distribution (Apt, Yum etc.) you should be able to add your own server as a source and have the VM keep itself updated without your users needing to do anything.
1
5
0
I'm using wxPython since about 2 years for several small scientific programs which I distribute to many Colleagues. I like wxPython and I'm already very familiar with it but there are few things which drive me crazy (not because of wxPython, actually I would like to continue to use it): 1) I have many users on different Operation systems. I know wxPython is cross platform but I have already no nerves and time to port all my small software’s (and more will come) every time to different Operation systems. Especially I'm not using some of them (Windows7, Mac), so it's hard for me to solve problems and user requests. 2) We update our software’s quite a lot (because all the time new ideas come from users and ourselves) which means for me to generate all standalones again, upload them and for the users to uninstall and install again. Nasty... I was thinking already to switch to Web Frameworks but there are some problems. First, many users like to use my software’s offline, e.g. when they travel or have no internet. Second we have some data in some databases which should NEVER go on a server. It’s all about patents and will be always a discussion, so I prefer to have some of my programs a standalone desktop application to simplify things. Others can be online, no problem. So, in general I would love a browser based solution, since everybody has a browser. I saw that some people ported Django projects as a standalone desktop application, which I found not a bad idea. I also red about Camelot but I think this is rather for databases. Camelot would be useful only for some of my tools which are rather a database searching and extraction programs. But other doesn’t use databases at all. Can anyone suggest me, what would be a good solution for my tools?
Python Desktop Applications
0.066568
0
0
3,254
10,284,847
2012-04-23T16:55:00.000
6
0
1
0
python,latex,matplotlib
44,506,534
4
false
0
0
Quick solutions plt.annotate("I am \n"+r"$\frac{1}{2}$"+"\n in latex math environment", xy=(0.5, 0.5))
1
24
0
I have a very basic question : how to do a line break with matplotlib in python with an "annotate" command. I tried "\" and "\n" but it does not work. And how to do this for a "Latex" annotation and for a normal text annotation ? Thank you very much.
Python : Matplotlib annotate line break (with and without latex)
1
0
0
40,716
10,285,748
2012-04-23T17:59:00.000
0
1
1
0
python
10,285,800
3
false
0
0
If all the arguments are known ahead, use an explicit argument list, optionally with default values, like def abc(arg1="hello", arg2="world",...). This will make the code most readable. When you call the function, you can use either abd("hello", "world") or abc(arg1="hello", arg2="world"). I use the longer form if there are more than 4 or 5 arguments, it's a matter of taste.
1
0
0
I am creating a module in python that can take multiple arguments. What would be the best way to pass the arguments to the definition of a method? def abc(arg): ... abc({"host" : "10.1.0.100", "protocol" : "http"}) def abc(host, protocol): ... abc("10.1.0.100", "http") def abc(**kwargs): ... abc(host = "10.1.0.100", protocol = "http") Or something else? Edit I will actually have those arguments (username, password, protocol, host, password2) where none of them are required.
What is the best way to pass multiple parameters to class init in python?
0
0
0
1,331
10,287,853
2012-04-23T20:34:00.000
0
1
0
1
python,ruby,usb,native
10,289,020
1
false
0
0
Well it is definitely possible; I don't know what the equivalent is in rubygems by pyUSB is a easy to use module you can leverage to do this and then there are numerous http libraries for python. As for making it self contained, it is possible but not ideal. py2exe is a program that basically takes a copy of the python interpreter, all dependencies used in your programs and your script and glues it all together in a exe file, but by default py2exe will not pack it into a exe, but there are instructions on the wiki
1
1
0
I'd like to develop an app that runs natively (self-contained executable) for both Mac and Windows that will detect/poll for a USB device being inserted and send an HTTP call as a result. I'm mainly a Ruby programmer, so ideally I could do this with a combination of Macruby/IronRuby and shared libraries, but it's looking like libusb requires a special driver to be installed on Windows (which I can't expect the clients to do). Are there libraries/gems that would facilitate this? Is it possible to do what I'm describing using Python/Ruby? It's not as important to be shared code as it is that the codebase is Python/Ruby/single language. libusb would be ideal if it didn't require an install of a special driver on Windows.
Cross-platform USB development for Mac/Windows - possible with Ruby/Python?
0
0
0
528
10,288,488
2012-04-23T21:18:00.000
0
1
1
0
java,c++,python,eclipse,visual-studio
10,288,556
1
false
0
0
To my knowledge, Eclipse has no support for multidebugger debugging. However, it might be possible to debug the same workspace in many Eclipse instance at the same time. Simply launch the debugger for each language separately by attaching to them as you said.
1
3
0
I have a software that uses multiple languages, which are all available as eclipse plugins (java, c++, python). The exes call each other. I was wondering if there is a way I could debug all these languages using eclipse. I have the sources for all of them, and all of them are projects in eclipse, but so far they work independently, and I was wondering whether, for example, if I added a break point in a C++ code and called a java program that calls the C++ code, the execution would pause when it reaches the C++ breakpoint. I think this is somehow similar to 'attaching to a process' in Visual Studio, though I'm not sure whether Visual Studio provides this feature either. Is it possible with eclipse or Visual Studio ?
multi language IDE
0
0
0
240
10,288,554
2012-04-23T21:24:00.000
2
0
0
0
python,python-3.x,tkinter
10,289,415
3
false
0
1
I've run into that exact same problem a couple times jaccarmac, and to my knowledge there is no way to find the width of a string of characters. Really the only way is to use the winfo_ commands: width, height, geometry. However, it kind of sounds like you just want to make sure that all of the text is displayed if you change the label and add more text. If that is the case, you don't have to worry about it. That should all be taken care of by the widgets themselves. If you don't see them expanding to show all of your label, that usually means one of the widgets containing that label is not set to expand (either using expand=YES with .pack, or columnconfigure(i, weight=1) for .grid). A final thought; in the pack arguments make sure it's YES, and not "yes". That uppercase YES is not a string, but a variable name defined by Tkinter.
2
1
0
I am trying to create a roguelike using the Text widget. I have figured out a few things, namely that I can set the size of the widget using width and height options and that I can find the pixel height or width of said widget. However, what I want to do is have the widget resizable (pack(expand="yes", fill="both")) but be able to refresh the displayed text on a resize. Is there a way to get the character dimensions when the widget is running without resorting to winfo_width() and math based on pixel dimensions of characters?
Finding The Current Size Of A tkinter.Text Widget
0.132549
0
0
1,580
10,288,554
2012-04-23T21:24:00.000
0
0
0
0
python,python-3.x,tkinter
10,290,058
3
true
0
1
There is no way to automatically get the width in characters, but it's easy to calculate, assuming you're using a fixed width font. One way to do this is to use the font_measure method of a font object. Use font_measure to get the width of a '0' (or any other character for that matter; I think tk users zero internally, not that it matters with a fixed width font), then use this in your calculations.
2
1
0
I am trying to create a roguelike using the Text widget. I have figured out a few things, namely that I can set the size of the widget using width and height options and that I can find the pixel height or width of said widget. However, what I want to do is have the widget resizable (pack(expand="yes", fill="both")) but be able to refresh the displayed text on a resize. Is there a way to get the character dimensions when the widget is running without resorting to winfo_width() and math based on pixel dimensions of characters?
Finding The Current Size Of A tkinter.Text Widget
1.2
0
0
1,580
10,295,327
2012-04-24T09:37:00.000
0
0
1
0
python,locale,string-conversion
10,295,512
1
true
0
0
You can make some assumptions on which character is the thousands separator and which is the decimal point. However, there is a case where you cannot know for sure what do do: Look for the last character that is . or ,. If it occurs more than once, the number does not have a decimal point and that character is the thousands separator If the string contains exactly one of each, the last one is the decimal point If the string contains only one point/comma, you are pretty much out of luck: 123.456 or 123,456 might be the number 123456 or 123.456. However, with a number like 123.45 - i.e. the number of digits after the potential thousands separator not being a multiple of three - you can assume that it's a decimal point.
1
0
0
I need to convert string to float, but there can be different input string formats, such as '1234,5' or '1234.5' or '1 234,5' or '1,234.5' or whatever. And I can not change locale decimal pointer or thousands separator, because I may not know what data I will get in advance. Is there a way or method or library to parse and convert to float this kind of locale-specific values without knowing which locale is used? P.S. Is there any solution exists for the same problem with dates? TIA.
Locale-indepenent string to float conversion in python
1.2
0
0
638
10,295,384
2012-04-24T09:41:00.000
1
0
0
0
python,checkbox,tkinter,message
10,296,668
1
true
0
1
No, the standard dialogs don't support that. If you want such a feature you'll have to build your own dialog out of a Toplevel window and other widgets.
1
2
0
I'm creating message boxes in Tkinter using tkMessageBox.showwarning. Does Tkinter let you insert a sort of checkbox with the message that says, for example, "do not show again" so when selected the message won't appear the next time?
"do not show message again" checkbox in Tkinter warning message
1.2
0
0
410
10,295,954
2012-04-24T10:16:00.000
0
0
0
1
python,google-app-engine
10,296,008
1
true
1
0
Try calling python appcfg.py update myapp/
1
0
0
I am new to google app engine and python. I have created an application in python with the help of google app engine. i am using cmmand 'appcfg.py update myapp/' from command prompt to update live code. this command was working perfectly but suddenly it stops working. Now every time i run this command it opens up the appcfg.py file. Please help me what is happening with the command
Updating app engine project code
1.2
0
0
270
10,298,104
2012-04-24T12:46:00.000
4
0
1
0
python,windows-installer,pywinauto
10,298,383
1
false
0
0
You need to launch "msiexec.exe" and pass the MSI as a command line parameter for it to be installed. You cannot launch directly an MSI as you would launch an EXE file. Example: msiexec.exe /i [MSI_path]
1
2
0
I am looking at using pywinauto in python to automate the installation of a Windows MSI installer for testing purposes. When I try to launch the MSI through the application.start I get the following error: "Error returned by CreateProcess: [Error 193] " Is it possible to even do this, or do I need to launch the MSI first and then connect to it, and if so, how do I achieve this? Thanks.
Using pywinauto to automate an MSI installer
0.664037
0
0
1,186
10,301,071
2012-04-24T15:27:00.000
2
0
1
0
python,python-idle
31,353,166
8
false
0
0
I may not be a Python expert/guru yet but this question is a user-experience / usability question more than anything. Some might say "Yeah, PEP 8 style guide... blah blah blah" but if I have the IDLE window a certain size (let's say small width), there's no reason I as a user shouldn't be able to scroll. It's simply poor user-experience as a result of poor design.
3
2
0
I am using IDLE to learn Python 2.7 on Windows 7. The Vertical scroll bar works fine but I cannot find a way to activate the Horizontal scroll bar. Is there a horizontal scroll bar in Python's IDLE? Thanks
Is there a horizontal scroll bar in python's idle?
0.049958
0
0
12,406
10,301,071
2012-04-24T15:27:00.000
2
0
1
0
python,python-idle
29,691,434
8
false
0
0
I'm using IDLE 2.7.3, Windows 7, and I can scroll horizontally by holding down the center mouse button/scroll wheel, and "dragging" around the cursor like that.
3
2
0
I am using IDLE to learn Python 2.7 on Windows 7. The Vertical scroll bar works fine but I cannot find a way to activate the Horizontal scroll bar. Is there a horizontal scroll bar in Python's IDLE? Thanks
Is there a horizontal scroll bar in python's idle?
0.049958
0
0
12,406
10,301,071
2012-04-24T15:27:00.000
1
0
1
0
python,python-idle
10,301,180
8
false
0
0
No, the text scrolls horizontally based on where the insertion point or selection is.
3
2
0
I am using IDLE to learn Python 2.7 on Windows 7. The Vertical scroll bar works fine but I cannot find a way to activate the Horizontal scroll bar. Is there a horizontal scroll bar in Python's IDLE? Thanks
Is there a horizontal scroll bar in python's idle?
0.024995
0
0
12,406
10,301,589
2012-04-24T15:58:00.000
4
0
1
0
python,list,dictionary,tuples
10,301,663
6
false
0
0
A dictionary value can't contain two tuples just by themselves. Each dictionary key maps to a single value, so the only way you can have two separate tuples associated with that key is for them to be themselves contained within a tuple or list: {'Key1':[(1.000,2.003,3.0029),(2.3232,13.5232,1325.123)]} - note the extra pair of square brackets. One way of doing this would be to get the current value associated with your key, and append it to a list before setting the new list back to that key. But if there's a possibility you'll need that for any key, you should do it for all keys right at the start, otherwise you'll get into all sorts of difficulties working out what level you're at.
1
4
0
I've been trying to figure out how to add multiple tuples that contain multiple values to to a single key in a dictionary. But with no success so far. I can add the values to a tuple or list, but I can't figure out how to add a tuple so that the key will now have 2 tuples containing values, as opposed to one tuple with all of them. For instance say the dictionary = {'Key1':(1.000,2.003,3.0029)} and I want to add (2.3232,13.5232,1325.123) so that I end up with: dictionary = {'Key1':((1.000,2.003,3.0029),(2.3232,13.5232,1325.123))} (forgot a set of brackets!) If someone knows how this can be done I'd appreciate the help as it's really starting to annoy me now. Thanks! Edit: Thanks everyone! Ironic that I tried that except at the time I was trying to make the value multiple lists instead of multiple tuples; when the solution was to just enclose the tuples in a list. Ah the irony.
How do you add multiple tuples(lists, whatever) to a single dictionary key without merging them?
0.132549
0
0
48,959
10,301,687
2012-04-24T16:04:00.000
0
1
1
0
python,compare
10,301,739
4
false
0
0
Don't know anything about python, but: how about sorting the file A into a particular order? Then you can go through file B line by line and do a binary search - more efficient.
1
0
0
I got txt file A with 300, 000+ lines and txt file B with 600, 000+ lines. Now what I want to do is to sift through file A line by line, if that line does not appear in file B then it will be appended to file C. Well, the problem is if I program like what I said above, it literally takes ages to finish all the job. So is there a better way to do this?
What's the fastest way to find unique lines from huge file A as compared to huge file B using python?
0
0
0
477
10,302,298
2012-04-24T16:45:00.000
9
0
1
1
python,debugging
10,302,538
1
true
0
0
The bdb module implements the basic debugger facilities for pdb.Pdb, which is the concrete debugger class that is used to debug Python scripts from a terminal. Unless you're planning to write your own debugger user interface, you shouldn't need to use anything from bdb.
1
8
0
I was looking through the Python standards libs and saw BDB the debugger framework. What is it for and can I get additional value from it? At the moment I use Eclipse/PyDev with the internal debugger which also supports conditionals breakpoints. Can I get something new from BDB?
What is BDB for in Python?
1.2
0
0
2,244
10,302,806
2012-04-24T17:18:00.000
0
0
1
0
python,pyinstaller
10,303,044
3
false
0
0
Try downloading Pyinstaller's latest development code. There they trying to implement GUI toolkit for building executables.
1
1
0
My Problem is the following: I want to create an script that can create other executables. These new executables have to be standalone, so they don't require any DLL's, etc. I know this is possible with PyInstaller, but only from console/command line. So essentially, what I want to do is make a python script that imports pyinstaller, creates another .py-file and uses pyinstaller to compile the new script to a .exe, so people who don't have python installed can use this program. EDIT: The script itself should only use one file, so it can also be a one-file executable
Is there a way to use PyInstaller inside another .py file?
0
0
0
1,598
10,304,280
2012-04-24T18:56:00.000
1
0
0
0
python,machine-learning,scikits,scikit-learn
10,308,680
1
true
0
0
We don't have that yet. You have to read the docstrings of the individual classes for now. Anyway, non linear models do not tend to work better than linear model for high dim sparse data such as text documents (and they can overfit more easily).
1
2
1
I'm getting a memory error trying to do KernelPCA on a data set of 30.000 texts. RandomizedPCA works alright. I think what's happening is that RandomizedPCA works with sparse arrays and KernelPCA don't. Does anyone have a list of learning methods that are currently implemented with sparse array support in scikits-learn?
python, scikits-learn: which learning methods support sparse feature vectors?
1.2
0
0
691
10,304,363
2012-04-24T19:01:00.000
1
0
0
0
python,django,web-deployment,source-code-protection
10,304,687
4
false
1
0
There is almost no scenario where your hosting provider would be interested in your source code. The source code of most websites just isn't worth very much. If you really feel it is necessary to protect your source code, the best thing to do is serve it from a system that you own and control physically and have exclusive access to. Failing that, there are a few techniques for obfuscating python, the most straightforward of which is to only push .pyc files and not .py files to your production server. However, this is not standard practice with Django because theft of web site source code by hosting providers is not really an extant problem. I do not know whether or not this technique would work with Django specifically.
4
3
0
I have picked up python/django just barely a year. Deployment of django site is still a subject that I have many questions about, though I have successfully manual deployed my site. One of my biggest questions around deployment is what measures can I take to safeguard the source code of my apps, including passwords in django's setting.py, from others, especially when my site runs on a virtual hosting provided by some 3rd party. Call me paranoid but the fact that my source code is running on a third-party server, which someone has the privileges to access anything/anywhere on the server, makes me feel uneasy.
What measures can I take to safeguard the source code of my django site from others?
0.049958
0
0
2,223
10,304,363
2012-04-24T19:01:00.000
1
0
0
0
python,django,web-deployment,source-code-protection
10,304,555
4
false
1
0
If someone has the privileges to access anything/anywhere on the server you can't do much, because what you can do others can do too, you can try some way of obfuscation but that will not work. Only solution is NOT to use such shared repository. Edit: options Keep working with shared repository if your data is not very sensitive Use dedicated hosting from companies like rack-space etc Use AWS to run your own instance Use google-app-engine server but that may require a DB change Run your own server (most secure)
4
3
0
I have picked up python/django just barely a year. Deployment of django site is still a subject that I have many questions about, though I have successfully manual deployed my site. One of my biggest questions around deployment is what measures can I take to safeguard the source code of my apps, including passwords in django's setting.py, from others, especially when my site runs on a virtual hosting provided by some 3rd party. Call me paranoid but the fact that my source code is running on a third-party server, which someone has the privileges to access anything/anywhere on the server, makes me feel uneasy.
What measures can I take to safeguard the source code of my django site from others?
0.049958
0
0
2,223
10,304,363
2012-04-24T19:01:00.000
0
0
0
0
python,django,web-deployment,source-code-protection
10,311,535
4
false
1
0
Protecting source code is not that important IMHO. I would just deploy compiled files and not worry too much about it. Protecting your config (specially passwords) is indeed important. Temia's point is good.
4
3
0
I have picked up python/django just barely a year. Deployment of django site is still a subject that I have many questions about, though I have successfully manual deployed my site. One of my biggest questions around deployment is what measures can I take to safeguard the source code of my apps, including passwords in django's setting.py, from others, especially when my site runs on a virtual hosting provided by some 3rd party. Call me paranoid but the fact that my source code is running on a third-party server, which someone has the privileges to access anything/anywhere on the server, makes me feel uneasy.
What measures can I take to safeguard the source code of my django site from others?
0
0
0
2,223