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
9,958,102
2012-03-31T17:33:00.000
0
0
1
0
python,regex
14,452,880
4
false
0
0
We can use this re.split(" ", "fat-free milk")
1
3
0
In Python, re.split("\W+", "fat-free milk") yields ['fat', 'free', 'milk']. How do I produce ['fat-free', 'milk'] from re.split()? I understand the problem to be that hyphens are not alphanumeric characters, but I'm not sure how to incorporate this fact into the regex. I have tried re.split("[(^\-)\W]+", "fat-free milk") to no avail.
How do I split words in Python while keeping in consideration words with hyphens?
0
0
0
1,856
9,960,524
2012-03-31T23:12:00.000
2
0
0
0
python,django,django-views
9,960,664
4
false
1
0
You could subclass RequestContext in django.template.context and redefine its __init__ method. You can then use this modified RequestContext in those particular views. The __init__ of RequestContext currently looks like this: def __init__(self, request, dict=None, processors=None, current_app=None, use_l10n=None): Context.__init__(self, dict, current_app=current_app, use_l10n=use_l10n) if processors is None: processors = () else: processors = tuple(processors) for processor in get_standard_processors() + processors: self.update(processor(request)) In here, get_standard_processors() returns the context processors defined in your settings. Before calling a context processor (last line of the above code), you could add a check that determines which processors need to be used and which ones need to be skipped.
1
0
0
I have a website with a menu. To generate the menu, I need some queries in the database. So I created a context processor to do it in all my views. Some of the views I have are actually forms. I get them using ajax and display them with jquery ui dialog, when my users click on some buttons. I can't remove all context processors for those pretty complex forms, I need the auth, static and il8n context processors in particular. But I don't want to make the menu based queries in the database to display those forms. Is there a way to exclude a context processor in a view ? I tried to put a variable in "request.session" in the view, then remove it and return an empty dictionary in my context processor. But it's pretty bad and there is possible concurrency issues. I can also parse the url in "request" in my context processor and return an empty dictionary, but it sounds like an hack again. Any idea or advice ? Thanks,
Django, exclude a context processor in a view
0.099668
0
0
2,637
9,960,583
2012-03-31T23:24:00.000
3
0
1
1
python,installation,cross-platform,python-3.2
9,960,652
5
false
0
0
Python is an interpreted, not a compiled language. So any standalone program you may want to distribute must bundle the entire interpreter inside it plus the libraries you used. This will result in an enormous file size for a single program. Also, this huge install cannot be used to run other python programs. An only marginally more complicated, but far better solution than this, is to just install the interpreter once and run any python program with it. I understand that the point of your question was to make a standalone executable, so I know I'm not answering it. But not being able to create executable standalones is one of the caveats of interpreted languages. However, a fundamental point here is about the whole objective of an interpreted language, which is a single interpreter with all the generic functions required to run any python code (which now happily needn't be any longer than they need to be). So you see, it's not really a caveat, this was the whole intention of interpreted languages. You might finally find a way to create a standalone python executable that runs on your friends' computers, but that would defeat the entire framework and idea behind an interpreted language.
1
15
0
Im new to python, but I was thinking about making a program with python to give to my friends. They don't know much about computers so if I asked them to install python by them selves they couldn't do it, but what if I could make an installer that downloads some version of python that only has what is needed for my file to run and make an exe file that would run the .py file in its own python interpreter . I also did a Google search and saw the freezing applications I could use to make the code into exe files to distribute (cx_freeze I use python 3.2), but not all of my friends have Windows computers and I rather Have my program so in each new version it auto updates by making a patch to .py file and not completely re-installing it . ** I am not looking for anything to make a stand alone executable . Just some kind of installer that bundles a minimalistic version of the python version your using . And an option to have an exe that is just a link to run the python file in the portable python interpreter, just for windows and a .sh file that would do the same for linux.
How do you make an installer for your python program
0.119427
0
0
28,302
9,960,675
2012-03-31T23:45:00.000
11
0
1
0
python,dictionary,namedtuple
9,960,784
2
true
0
0
From an API viewpoint, probably not much, though: namedtuple keys are always strings with some limitations: Any valid Python identifier may be used for a fieldname except for names starting with an underscore. Valid identifiers consist of letters, digits, and underscores but do not start with a digit or underscore and cannot be a keyword such as class, for, return, global, pass, or raise. namedtuples can always be accessed as regular tuples. Internally they are very different: Named tuple instances do not have per-instance dictionaries, so they are lightweight and require no more memory than regular tuples.
1
5
0
I know there is no frozen dict data type but If there was one how would it be different from namedtuple. It seems to me that namedtuple performs the required operations but obviously it does not. So what are the differences?
Difference between namedtuple and a frozen dict
1.2
0
0
1,536
9,961,190
2012-04-01T01:28:00.000
5
1
1
0
python,eclipse,pydev
9,961,465
1
false
0
0
File > Import > "General" Folder > "File System" Folder > "Browse" button
1
3
0
I've recently started using eclipse for my class over IDLE. So far I have no problems writing new code and creating new projects in eclipse. However, when I open older code that was not originally written in my current project, eclipse seems to only open it as a text file. For example, when I want to run a piece of code, I get a popup asking for an ANT build instead of running it using pydev. Also the code will not show up in the pydev package explorer. How do I go about importing the source code into my project so eclipse will treat it as such.
Python: Import Source Code into Eclipse
0.761594
0
0
5,598
9,961,357
2012-04-01T02:03:00.000
12
0
0
1
python,reload,tornado,restart
9,961,405
2
true
0
0
If you are looking for automatic reloading of .py files during development. In your tornado.web.Application() put debug=True after your handlers. I don't think you should do this in production environment, because such implementation typically use a background thread to actively scan files for changes, which may slow down your application.
1
12
0
I just start learning Python + Tornado for my web servers. Every time I modify some code on my python scripts or templates I have to stop the in my terminal (CTRL+C) and restart it (python server.py) and I want a more effective way to do this, that after modifying code in some files the server automatically restarts. Previously I working with NodeJS and using supervisor to do this. Also there is a way to reload my tab in Google Chrome so I can see the changes without reloading (F5) Currently I'm using Ubuntu 11.10 and Sublime Text 2 and using CTRL+B on sublime text, but if the server is already running generates an error because the address and port is in use. There is a fix for that without changing the port. Thanks.
Python + Tornado Restart after editing files
1.2
0
0
6,556
9,961,456
2012-04-01T02:30:00.000
0
0
0
0
python,wxpython,wxwidgets
9,963,895
2
false
0
1
Create a new control by inheritance from the slider. The only change from the base slider control is that you override the method that handles mouse click events, Your method needs to do two things: call the routine that you use to 'skip the video to the mouse click' and call the base slider control mouse click handler so it can look after the visual feedback details.
1
3
0
I wish to emulate or most media players' sliders - where clicking anywhere on the slider widget skips the video to that position. How can I get the slider's value under the mouse click and set the value to that? By default, when clicked on the slider, it only scrolls by a Pagesize at a time, not scrolls to the position user clicked.
Get wxpython slider's value under mouse click
0
0
0
1,615
9,963,806
2012-04-01T10:51:00.000
0
0
0
0
python
9,965,553
1
false
0
1
Import tkinter as you would usually do so, and create your popup. It would be best to stay within pygame though, using tkinter and pygame would end up being pretty complicated.
1
0
0
I need to have a pygame window check if the user right clicked (I can do) and then make a popup menu to display options using TKinter (?). Is this possible?
Pygame using TKinter to make a popup menu?
0
0
0
338
9,965,062
2012-04-01T14:18:00.000
1
0
0
0
python,treeview,web
9,965,972
2
true
1
0
This isn't really a python or django issue: presentation on the web is done using (X)HTML, other types of XML (such as SVG), and javascript to automate the client side. Go ahead and use django for your project, but understand that to do this, you will need to also get the hang of (at least) a javascript library for this task.
2
0
0
I'm new to Python and web development (although I have development experience with Client/Server apps .. a little rusty), and I need to build a Python web application that populates an interactive tree from a database (for my PG degree). I've tried PyQT4 which contains a QTreeView/QTreeWidget but couldn't run this form as a web application. I've used QT Designer to build such form but couldn't make it run as a web app. From Google search (over two weeks) I know that Django is the best framework to build a web app for Python, but it doesn't have an interactive tree viewer (am I right?). I'm very confused at the moment and don't actually know where to go from here. I'd appreciate your help in answering the following critical questions: Can Django help in building such application? i.e. Does it support web tree view? Can I use QTreeView from PyQt with Django? or even can I build a web application directly using PyQT and QT Designer? If neither are suitable; Your suggestions are very much appreciated.
Building a tree in a web app using Python
1.2
0
0
1,635
9,965,062
2012-04-01T14:18:00.000
0
0
0
0
python,treeview,web
9,965,636
2
false
1
0
google django treeview for a few implementations. Alternativly use JavaScript. Django and Javascript play nicely and there are loads of JavaScript Treeview implementations.
2
0
0
I'm new to Python and web development (although I have development experience with Client/Server apps .. a little rusty), and I need to build a Python web application that populates an interactive tree from a database (for my PG degree). I've tried PyQT4 which contains a QTreeView/QTreeWidget but couldn't run this form as a web application. I've used QT Designer to build such form but couldn't make it run as a web app. From Google search (over two weeks) I know that Django is the best framework to build a web app for Python, but it doesn't have an interactive tree viewer (am I right?). I'm very confused at the moment and don't actually know where to go from here. I'd appreciate your help in answering the following critical questions: Can Django help in building such application? i.e. Does it support web tree view? Can I use QTreeView from PyQt with Django? or even can I build a web application directly using PyQT and QT Designer? If neither are suitable; Your suggestions are very much appreciated.
Building a tree in a web app using Python
0
0
0
1,635
9,965,725
2012-04-01T15:41:00.000
0
0
1
1
python,google-app-engine,shared-libraries
9,965,775
2
false
0
0
The deploy tools for Google App Engine (in the Python world at least) don't know anything about shared projects in Eclipse. You point the deploy script to a folder and that's about it. You can create a script that will copy the projects into a deploy folder and deploy that folder.
2
2
0
I want to share some modules between a python GAE project, and another python project but want to use the same source files so that I can change them without having to worry about keeping the source files in each project up to date. Is there a way to let two python projects share the same source files outside of their root? Also let GAE know which source files exist outside of the source tree so it deploys them to the server. I'm using PyDev on Eclipse.
Is it possible to have shared python library in GAE?
0
0
0
161
9,965,725
2012-04-01T15:41:00.000
4
0
1
1
python,google-app-engine,shared-libraries
9,968,299
2
true
0
0
IF your dev environment is linux, you can use symlinks in your project folder to the shared source. The deployment will treat the symlinks as actual files/folders.
2
2
0
I want to share some modules between a python GAE project, and another python project but want to use the same source files so that I can change them without having to worry about keeping the source files in each project up to date. Is there a way to let two python projects share the same source files outside of their root? Also let GAE know which source files exist outside of the source tree so it deploys them to the server. I'm using PyDev on Eclipse.
Is it possible to have shared python library in GAE?
1.2
0
0
161
9,965,881
2012-04-01T16:02:00.000
3
0
1
1
python
9,965,932
4
false
0
0
You cannot do this without cooperation with operating system. Whatever you do, Ctrl-Alt-Del will allow the user to circumvent your lock.
3
0
0
Is there any way I can create a UAC-like environment in Python? I want to basically lock the workstation without actually using the Windows lock screen. The user should not be able to do anything except, say, type a password to unlock the workstation.
Take all input in Python (like UAC)
0.148885
0
0
507
9,965,881
2012-04-01T16:02:00.000
1
0
1
1
python
9,968,755
4
false
0
0
I would try with pygame, because it can lock mouse to itself and thus keep all input to itself, but i wouldn't call this secure without much testing, ctr-alt-del probably escape it, can't try on windows right now. (not very different of Bryan Oakley's answer, except with pygame)
3
0
0
Is there any way I can create a UAC-like environment in Python? I want to basically lock the workstation without actually using the Windows lock screen. The user should not be able to do anything except, say, type a password to unlock the workstation.
Take all input in Python (like UAC)
0.049958
0
0
507
9,965,881
2012-04-01T16:02:00.000
1
0
1
1
python
9,966,066
4
true
0
0
You might be able to get the effect you desire using a GUI toolkit that draws a window that covers the entire screen, then do a global grab of the keyboard events. I'm not sure if it will catch something like ctrl-alt-del on windows, however. For example, with Tkinter you can create a main window, then call the overrideredirect method to turn off all window decorations (the standard window titlebar and window borders, assuming your window manager has such things). You can query the size of the monitor, then set this window to that size. I'm not sure if this will let you overlay the OSX menubar, though. Finally, you can do a grab which will force all input to a specific window. How effective this is depends on just how "locked out" you want the user to be. On a *nix/X11 system you can pretty much completely lock them out (so make sure you can remotely log in while testing, or you may have to forcibly reboot if your code has a bug). On windows or OSX the effectiveness might be a little less.
3
0
0
Is there any way I can create a UAC-like environment in Python? I want to basically lock the workstation without actually using the Windows lock screen. The user should not be able to do anything except, say, type a password to unlock the workstation.
Take all input in Python (like UAC)
1.2
0
0
507
9,968,040
2012-04-01T20:29:00.000
4
0
0
0
python,google-app-engine,video,mp3
9,968,088
3
true
1
0
You don't want todo this in Python, video convert requires working native modules which the App Engine doesn't support. You can try to work 3rd party web service that do the convert for you, or send the convert task to an external server.
2
3
0
I'm working on a project, using Python running on Google App Engine. The project must allow users to upload video file then convert these files into mp3 audio file. Is there a way to convert this video to mp3/wav audio? Could anyone offer a solution to this? Thanks in advance.
Convert video(any type) to audio -mp3 format- using python
1.2
0
0
3,509
9,968,040
2012-04-01T20:29:00.000
2
0
0
0
python,google-app-engine,video,mp3
9,968,089
3
false
1
0
You're going to have trouble doing this on GAE, as libraries with native components aren't necessarily available there; it may well not be possible at all. If targeting a more typical Python app server environment, rather than GAE, I would do this using the GStreamer Python bindings; GStreamer lets you set up a media pipeline (decoders/demuxers/encoders, etc), and is otherwise perfect for this application (other than platform availability).
2
3
0
I'm working on a project, using Python running on Google App Engine. The project must allow users to upload video file then convert these files into mp3 audio file. Is there a way to convert this video to mp3/wav audio? Could anyone offer a solution to this? Thanks in advance.
Convert video(any type) to audio -mp3 format- using python
0.132549
0
0
3,509
9,969,649
2012-04-02T00:38:00.000
2
0
1
0
list,python-3.x,tuples
67,201,077
3
false
0
0
In Python, there are two types of data structures: list and tuple. The list has dynamic properties, while the tuple has static ones. In other languages, lists are declared similarly to arrays. Lists don't have to be homogeneous all of the time, which makes it Python's most effective tool. The list is a type of container in Python's Data Structures that is used to store several pieces of data at once. Lists are a good way to keep track of a sequence of data and iterate over it. Tuple is a sequence data form that can contain elements of various data types, but it is immutable. In other words, a tuple is a comma-separated list of Python properties. Because of its static existence, the tuple is quicker than the array. Here are some differences I managed to get; Lists are mutable Tuples are immutable Lists - Implication of iterations is Time-consuming. Tuple - The implication of iterations is comparatively Faster. Lists -The list is better for performing operations, such as insertion and deletion. Tuple -Tuple data type is appropriate for accessing the elements. Lists -Lists consume more memory. Tuple -Tuple consume less memory as compared to the list. Lists -Lists have several built-in methods. Tuple -Tuple does not have many built-in methods. Lists -The unexpected changes and errors are more likely to occur. Tuple -In tuple, it is hard to take place. Hope you understand.
2
8
0
I have known for a while that the primary difference between lists and tuples in Python is that lists are mutable and tuples are not. Beyond that and the different methods available to them, I know very little about lists and tuples. Is there any other difference between them? Are there any advantages/disadvantages (aside from immutability) in using a tuple over a list in Python 3? Does one have a faster access time, or have a smaller memory size, or contain more methods, than the other? Are their internal structures different in any way? Or is a tuple just an immutable list, nothing more?
Difference between list and tuple (minus immutability) in Python?
0.132549
0
0
3,307
9,969,649
2012-04-02T00:38:00.000
7
0
1
0
list,python-3.x,tuples
10,296,694
3
true
0
0
Both lists and tuples are internally implemented as arrays of references to the element objects. This way, both can be indexed and both require the same amount of memory for each element. Internally, they are both homogeneous (untyped references). Logically, they are both heterogeneous (automatic dereferencing, the type is bound to the target object). The list can be modified, so the internal array is a dynamic array. The tuple cannot be modified, so it is internally just fixed-size array. From that point of view, tuples are simpler. For which is faster or not, you can measure the concrete situation using the timeit module. You should be aware of the fact that tuples are immutable only with respect to the number and to values of the stored references. If (say) a list is used as one of the tuple elements, the list content can be changed. This way, logically, the tuple content is not constant (such tuple is not hashable). Use whatever type is better for the purpose. There is no strict preference. It depends on the situation.
2
8
0
I have known for a while that the primary difference between lists and tuples in Python is that lists are mutable and tuples are not. Beyond that and the different methods available to them, I know very little about lists and tuples. Is there any other difference between them? Are there any advantages/disadvantages (aside from immutability) in using a tuple over a list in Python 3? Does one have a faster access time, or have a smaller memory size, or contain more methods, than the other? Are their internal structures different in any way? Or is a tuple just an immutable list, nothing more?
Difference between list and tuple (minus immutability) in Python?
1.2
0
0
3,307
9,969,863
2012-04-02T01:17:00.000
5
0
1
0
python
9,969,876
3
true
0
0
If it requires a filename, then you're going to have to create a file. (And that's poor design on the part of the library creators.)
1
5
0
I am beginner in python, and I need to use some thirdparty function which basically has one input - name of a file on a hard drive. This function parses file and then proceses it. I am generating file contents in my code (it's CSV file which I generate from a list) and want to skip actual file creation. Is there any way I can achieve this and "hack" the thirdparty function to accept my string without creating a file? After some googling I found StringIO, and created a file object in it, now I am stuck on passing this object to a function (again, it accepts not a file object but a file name).
python: pass string instead of file as function parameter
1.2
0
0
4,431
9,970,598
2012-04-02T03:35:00.000
0
0
0
0
python,django,apache2,mod-wsgi
9,971,145
4
false
1
0
Delete any .pyc files from your code base directory, and restart the server.
3
1
0
I'm running mod_wsgi on apache2. It's running Django and for some reason, after I change my code, old versions are sometimes shown along with new code. For example, after creating a view that simply returns an Http Response with "Hi", I get either the Django start page or "Hi". Any ideas what would cause this? Thanks.
mod_wsgi showing old code
0
0
0
559
9,970,598
2012-04-02T03:35:00.000
2
0
0
0
python,django,apache2,mod-wsgi
9,970,706
4
true
1
0
apache2/mod_wsgi keeps parts of the application loaded between requests. You have to restart the server after code updates.
3
1
0
I'm running mod_wsgi on apache2. It's running Django and for some reason, after I change my code, old versions are sometimes shown along with new code. For example, after creating a view that simply returns an Http Response with "Hi", I get either the Django start page or "Hi". Any ideas what would cause this? Thanks.
mod_wsgi showing old code
1.2
0
0
559
9,970,598
2012-04-02T03:35:00.000
0
0
0
0
python,django,apache2,mod-wsgi
9,970,690
4
false
1
0
This could possibly be your browser caching responses from the server. Try disabling caching to see if that has any affect. Even if it doesn't now, doing so can potentially save you a lot of grief and confusion in the future.
3
1
0
I'm running mod_wsgi on apache2. It's running Django and for some reason, after I change my code, old versions are sometimes shown along with new code. For example, after creating a view that simply returns an Http Response with "Hi", I get either the Django start page or "Hi". Any ideas what would cause this? Thanks.
mod_wsgi showing old code
0
0
0
559
9,974,465
2012-04-02T10:09:00.000
2
0
0
0
python,django,wsgi,django-wsgi
9,974,529
2
true
1
0
Run the app inside a virtualenv.
1
0
0
I have an application that uses Django 1.3 installed in python's site-packages. I want to create another copy of it (WSGI under Apache) but make it use a newer version of Django I've unpacked alongside to see if any input is required before I'm able to migrate to 1.4. Is there a way to somehow specify where WSGI should import Django from?
Running WSGI application with a different version of Django to what's installed in python site-packages?
1.2
0
0
181
9,974,611
2012-04-02T10:18:00.000
1
1
1
0
python,zeromq,pyzmq
9,975,162
2
false
0
0
Are you sure that zmq is installed on computer? If not then try installing it. In ubuntu it is quite easy sudo apt-get install python-zmq
1
0
0
I have a zmq directory in cwd . when i import zmq from a python file running under apache it gives me import error. but when i import zmq using console from current directory it imports. How to make this import possible from anywhere in my server?
python import error when importing zmq
0.099668
0
0
2,387
9,976,293
2012-04-02T12:19:00.000
0
0
1
0
python,algorithm
9,978,452
2
false
0
0
How about representing the times a switch is enabled as a list of minutes of the day when a switch is enabled, e.g. A=[600, 601, 602, ..., 659, ..., ], where 10am corresponds to minute 600 in the day. Convert the lists to sets and use a sum of the intersections.
1
2
0
I've been thinking hard for a long time but couldn't work this out. Consider the following sequences over time, which records the status of switches: A = [(10:00, 1), (11:00, 0), (12:00, 1), (12:30, 0),..., (23:00, 1)] # switch A is on at 10:00, off at 11:00 and so on B = [(10:30, 1), (11:15, 0), (11:30, 1), (12:15, 0),..., (23:30, 0)] # likewise C = ... (In reality the time is in the format of python's time.struct_time.) So basically the structure would be [(time1, status1), (time2, status2)...]. The lists contains data within 24h, and only the switching instances are recorded (so the adjacent "status"es are always opposite to each other). I want to calculate the total amount of time, when all switches A,B,C are on. This seemingly simple question is taking me many days to come up with something useful.
calculate amount of time intersection when all sequences fulfill certain criteria?
0
0
0
163
9,977,888
2012-04-02T14:00:00.000
0
0
0
0
php,python,database,windows,linux
9,978,197
2
false
0
0
You can't. It looks that there is no way to identify the file: neither by content nor by pathname. One workaround might be: use path as id (and use them as reference in the DB) and do not use system tools (like mv) to move files but your own script which updates the file system and the database.
1
0
0
I'm trying to implement an script that reads the content(files and folders) of a certain directory and writes it in a database. My goal is create an software that allows me to organize those files and folders relating description and tags to them, without affecting the correspondig physical files in the disk. But for now I'm facing a logical problem: How do I make a direct connection between that physical file and the database register? I want that, even if the physical file, for some reason, is edited or moved to another folder inside the root directory, the software is still able to relate that file with its original register in the database. My first idea was to use a checksum hash to identify every file but, I'm guessing that if the file is edited, so does the hash, doesn't it? Besides that, I also think that a folder itself can't be checked that way. Another solution that came up to my mind was applying a unique key in the beginning of every file and folder name in the directory. That may work, but it seems to me like an improvised solution and, therefore, I'mhoping that there may be another way to do it that I haven't considered yet. Does anyone have an advice on that?
How to link a file to a database?
0
1
0
114
9,978,862
2012-04-02T15:08:00.000
0
0
0
0
javascript,python,ironpython,client-side
9,979,094
3
false
1
0
Given the server limitation, I would run those scripts locally to generate HTML, and push that static output onto your server.
1
0
0
I have a small website hosted by my university. The policy is that no server side scripting language (e.g. PHP, etc.) is enabled, hence websites are either static or can use client side scripting (e.g. javascript, etc.). I also can't touch the server/configure it/install things. Anyway, I wanted to add some data from other websites (namely, google scholar citations) that I manage to scrape with Python+lxml, dynamically. Is there any way I can have these data dynamically queried - on the client side of course? I tried using IronPython to embed my Python code in my webpage, but it was complaining about failing to find the lxml imported library. But a similar solution would be great. Or a library in pure javascript which allows for opening and parsing external webpages...? Thanks!
Alternative to a server side scripting language for scraping
0
0
1
682
9,979,326
2012-04-02T15:38:00.000
0
0
0
0
python,frameworks,web-frameworks
9,979,501
8
false
1
0
Python works well using CGI. that's the simplest thing you can do: it only needs apache and a working python environment, and is the closest to a standard php setup. remember that, when using CGI, your python script is responsible for outputting the necessary HTTP headers (sys.stdout.write('Content-Type: text/html\n\n')), but there is a CGI module which is part of the python standard library which greatly helps dealing with the raw stuffs (post/get arguments parsing, header retrieval, header generation).
3
8
0
I would like to know if there is a way to create web pages without a huge framework in python. I think of something like PHP/Apache, which comes just as a language and not with to much overhead (but I don't like PHP...). In PHP there is no ORM, no template engine, etc. But it is very very easy to just print a Hello World to the browser. I know about Django and really like it, but it is a bit too big for simple web portals (5-10 pages). I really like something simple, without installing too much.
Python: How to create simple web pages without a huge framework?
0
0
0
18,361
9,979,326
2012-04-02T15:38:00.000
1
0
0
0
python,frameworks,web-frameworks
9,979,395
8
false
1
0
I'm not sure what's wrong with django flatpages for your purposes. Another alternative would be to replace the django template system with something more powerful, like jinja, so you can write your tag soup and do processing there, with minimal logic in the view. In practice (given that you already know django), that is likely to be easier than using a microframework (which requires more of the programmer, in exchange for being completely unopinionated about anything).
3
8
0
I would like to know if there is a way to create web pages without a huge framework in python. I think of something like PHP/Apache, which comes just as a language and not with to much overhead (but I don't like PHP...). In PHP there is no ORM, no template engine, etc. But it is very very easy to just print a Hello World to the browser. I know about Django and really like it, but it is a bit too big for simple web portals (5-10 pages). I really like something simple, without installing too much.
Python: How to create simple web pages without a huge framework?
0.024995
0
0
18,361
9,979,326
2012-04-02T15:38:00.000
4
0
0
0
python,frameworks,web-frameworks
9,979,487
8
false
1
0
I've used Flask (and bottle.py) in the past, but these days I actually prefer Pyramid, from the Pylons folks. Pyramid is capable of being a large, full-fledged framework, is designed for flexibility, and has no shortage of plugins and extensions available adding additional functionality -- but it also is capable of small, single-file projects; see this tutorial for an example. Going with Pyramid will give you room to grow if your needs expand over time, while still retaining the ability to start small.
3
8
0
I would like to know if there is a way to create web pages without a huge framework in python. I think of something like PHP/Apache, which comes just as a language and not with to much overhead (but I don't like PHP...). In PHP there is no ORM, no template engine, etc. But it is very very easy to just print a Hello World to the browser. I know about Django and really like it, but it is a bit too big for simple web portals (5-10 pages). I really like something simple, without installing too much.
Python: How to create simple web pages without a huge framework?
0.099668
0
0
18,361
9,979,602
2012-04-02T15:55:00.000
23
0
1
0
python
9,979,626
10
true
0
0
Put them in a list, sort them, pick the middle one.
1
8
0
Given 3 numbers, I need to find which number lies between the two others. ie,given 3,5,2 I need 3 to be returned. I tried to implement this by going thru all three and using if else conditions to check if each is between the other two.But this seems a naive way to do this.Is there a better way?
how to find the middle number in python
1.2
0
0
55,236
9,980,270
2012-04-02T16:37:00.000
1
0
0
0
python,image-processing,binary
9,982,670
4
false
0
0
A combination of erosion and dilation (and vice versa) on a binary image can help to get rid of salt n pepper like noise leaving small lines intact. Keywords are 'rank order filters' and 'morphological filters'.
1
0
1
I have a binary image with contour lines and need to purify each contour line of all unnecessary pixels, leaving behind a minimally connected line. Can somebody give me a source, code example or further information for this kind of problem and where to search for help, please?
Thinning contour lines in a binary image
0.049958
0
0
6,610
9,980,517
2012-04-02T16:57:00.000
1
0
1
0
python,web-crawler,python-2.7
9,980,811
3
true
0
0
You could create a class that has an index number of the line from seed_list.txt, the URL, and where the data from the web. An object of this type can be created with the line number and URL, then it is passed to the worker thread which will put the data into the object, and then the object is passed to a write thread which will order the objects by the line number and output the data as necessary.
3
2
0
I am writing a web crawler that processes multiple URLs at the same time and works in the following way: It gets a URL from a list of URLs included in seed_list.txt, It crawls it and write the data into data.txt; just like how most of web crawlers work. When I make it single-threaded, I can get the data in data.txt in the same order with that of the URLs in seed_list.txt, but when it's multi-threaded, I don't seem able to control it, as each thread writes the data to data.txt once it is finished. Is there a way I can make my web crawler multi-threaded but keep the original order? Thank you very much! @Lance, Ignacio, and Maksym, thank you all for your help - your answers definitely point me in the right direction.
Processing Order of Python's Threading Module
1.2
0
1
167
9,980,517
2012-04-02T16:57:00.000
2
0
1
0
python,web-crawler,python-2.7
9,980,555
3
false
0
0
Create an additional thread that is responsible for enumerating results from each of the crawler threads.
3
2
0
I am writing a web crawler that processes multiple URLs at the same time and works in the following way: It gets a URL from a list of URLs included in seed_list.txt, It crawls it and write the data into data.txt; just like how most of web crawlers work. When I make it single-threaded, I can get the data in data.txt in the same order with that of the URLs in seed_list.txt, but when it's multi-threaded, I don't seem able to control it, as each thread writes the data to data.txt once it is finished. Is there a way I can make my web crawler multi-threaded but keep the original order? Thank you very much! @Lance, Ignacio, and Maksym, thank you all for your help - your answers definitely point me in the right direction.
Processing Order of Python's Threading Module
0.132549
0
1
167
9,980,517
2012-04-02T16:57:00.000
1
0
1
0
python,web-crawler,python-2.7
9,980,948
3
false
0
0
You can run a special thread which outputs data and interact with it through a queue. I mean your 'crawling' thread will not write a result to a text file but put it to the queue. This 'output' thread can sort/filter your results.
3
2
0
I am writing a web crawler that processes multiple URLs at the same time and works in the following way: It gets a URL from a list of URLs included in seed_list.txt, It crawls it and write the data into data.txt; just like how most of web crawlers work. When I make it single-threaded, I can get the data in data.txt in the same order with that of the URLs in seed_list.txt, but when it's multi-threaded, I don't seem able to control it, as each thread writes the data to data.txt once it is finished. Is there a way I can make my web crawler multi-threaded but keep the original order? Thank you very much! @Lance, Ignacio, and Maksym, thank you all for your help - your answers definitely point me in the right direction.
Processing Order of Python's Threading Module
0.066568
0
1
167
9,986,059
2012-04-03T01:38:00.000
0
1
0
1
python,security,passwords,pipe
9,986,152
2
false
0
0
Tough problem. If you have access to source code of the program in question, you can change argv[0] after startup. On most flavors of *nix, this will work. The config file approach may be better from a security perspective. If the config file can be specified at run time, you could generate a temp file (see mkstemp), write password there, and invoke subprocess. You could even add a small delay (to give subprocess time to do its thing) and possibly even remove the config file. Of course the best solution is to change the program in question to read password from stdin (but it sounds like you already knew that)
2
0
0
I have a program (not written by me) that I would like to use. It authenticates to an online service using a username and password that I would like to keep private. The authentication information may be passed to the program in two ways: either directly as command-line arguments or via a plaintext configuration file, neither of which seem particularly secure. I would like to write a Python script to manage the launching of this program and keep my credentials away from the prying eyes of other users of the machine. I am running in a Linux environment. My concerns with the command-line approach are that the command line used to run the program is visible to other users via the /proc filesystem. Likewise, a plaintext configuration file could be vulnerable to reading by someone with the appropriate permissions, like a sysadmin. Does anyone have any suggestions as to a good way to do this? If I had some way of obscuring the arguments used at the command line from the rest of the system, or a way to generate a configuration file that could be read just once (conceptually, if I could pipe the configuration data from the script to the program), I would avoid the situation where my credentials are sitting around potentially readable by someone else on the system.
Securely passing credentials to a program via plaintext file or command line
0
0
0
1,344
9,986,059
2012-04-03T01:38:00.000
0
1
0
1
python,security,passwords,pipe
9,986,183
2
false
0
0
About the only thing you can do in this situation is store the credentials in a text file and then deny all other users of the machine permissions to read or write it. Create a user just for this script, in fact. Encrypting doesn't do much because you still have to have the key in the script, or somewhere the script can read it, so it's the same basic attack.
2
0
0
I have a program (not written by me) that I would like to use. It authenticates to an online service using a username and password that I would like to keep private. The authentication information may be passed to the program in two ways: either directly as command-line arguments or via a plaintext configuration file, neither of which seem particularly secure. I would like to write a Python script to manage the launching of this program and keep my credentials away from the prying eyes of other users of the machine. I am running in a Linux environment. My concerns with the command-line approach are that the command line used to run the program is visible to other users via the /proc filesystem. Likewise, a plaintext configuration file could be vulnerable to reading by someone with the appropriate permissions, like a sysadmin. Does anyone have any suggestions as to a good way to do this? If I had some way of obscuring the arguments used at the command line from the rest of the system, or a way to generate a configuration file that could be read just once (conceptually, if I could pipe the configuration data from the script to the program), I would avoid the situation where my credentials are sitting around potentially readable by someone else on the system.
Securely passing credentials to a program via plaintext file or command line
0
0
0
1,344
9,987,913
2012-04-03T06:06:00.000
-6
0
1
0
python,regex
9,987,948
5
false
0
0
Use [a-zA-Z] to match all the alphabet characters.
1
8
0
I'm looking for the equivalent of [\w]&&[^\d] (Of course && is not a regex operator). The regex needs to match ONLY words made up of UTF8 "alphabet" characters. Does anyone have any ideas?
What Python regex matches all alphabet characters but no numbers? [unicode aware]
-1
0
0
16,695
9,988,578
2012-04-03T07:01:00.000
2
1
1
0
python
9,988,597
2
true
0
0
can mighty Python do it for me? No, you have to do it yourself (by having every instance of B keep a reference to the corresponding instance of A).
1
1
0
Assuming I have a instance of class A (name it AI) that has an instance of class B (name it BI). Can a reference to BI (somewhere else) tell me that it is part of AI? I don't talk about inheritance/parent class. I know I can do this by implementing a reference to A in the constructor of B - but can mighty Python do it for me?
Get containing python class from element
1.2
0
0
429
9,990,358
2012-04-03T09:15:00.000
1
0
0
1
python,dll,windows-7,pylucene
10,012,400
1
true
0
0
The answer is probably, that if something like that happens to you, there is a wrong DLL somewhere in the path that is called first (and puttting the DLL in system32 ensures it is first). So if you put the relevant DLL in your PATH - make sure it is the first (or look into each element to find out who is getting ahead of you) Answered myself for future reference for people
1
0
0
Finally I managed to get pylucene working on my windows7 machine, Which raised a more general question: How come that when I have a dll on a directory in the path, python couldn't find it, and when I put the dll in c:\windows\system32 - it did work? Using windows 7 32 bit
dll in a different directory than c:\windows\system32
1.2
0
0
239
9,991,838
2012-04-03T10:56:00.000
4
0
1
0
python,linux,shell,ipython,line-breaks
9,991,864
3
true
0
0
Nothing is the problem. Python code is executed line-by-line. If your code does not work when executed line-by-line, it should not work when loaded from a file (assuming in both cases a "clean" environment).
2
8
0
Hi I'm new to Linux and I really like the idea of writing and testing python code in a shell. But my problem is how can I do line breaks in IPython. Every time I use the (I think) "normal" shortcut shift+enter the code gets executed. Function keys are disabled and keyboard layout works fine on my laptop, what could be the problem?
Linux - Linebreak in IPython
1.2
0
0
7,327
9,991,838
2012-04-03T10:56:00.000
7
0
1
0
python,linux,shell,ipython,line-breaks
9,992,118
3
false
0
0
If you want to do a line-break, you end the line with the \ escape character, same as you do in a Python file. Shift+Enter doesn't have any special meaning in ipython, and indeed most over places in the shell. It doesn't have special meaning in Python, either. It does have special meaning in some text editors and word processors, most notably LyX and LibreOffice, and of course on some websites (through a web browser).
2
8
0
Hi I'm new to Linux and I really like the idea of writing and testing python code in a shell. But my problem is how can I do line breaks in IPython. Every time I use the (I think) "normal" shortcut shift+enter the code gets executed. Function keys are disabled and keyboard layout works fine on my laptop, what could be the problem?
Linux - Linebreak in IPython
1
0
0
7,327
9,991,854
2012-04-03T10:57:00.000
0
0
0
0
python,unicode,utf-8,sqlite
9,991,929
1
false
1
0
You should .decode with the correct encoding. In this case Latin 1 or CP1252. »ö« is obviously not 0xf6 in UTF-8 so why should it work?
1
0
0
I am requesting a web page and want to cache the page data as a raw html string. (First I escaped the data string) I use sqlite3 to save my data on. When I tried give the byte_string in dictionary, or tuple, using placeholders in request, it raise "Programming Error" saying to convert the application to use unicode strings. I save it as SQLITE3 TEXT datatype. I tried data.encode("utf-8") and encode("utf-8") both raises the same error UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 11777: invalid start byte I know it contains a strange character, this character is 'ö'. How can i solve this problem. Do i need use BLOB datatype of sqlite3
How to convert a stringbyte(raw html string) to sqlite3 TEXT supporting unicode in Python
0
1
0
241
9,993,899
2012-04-03T13:06:00.000
1
1
1
0
python,plugins,adhoc
9,993,949
2
true
0
0
You can simply import the modules (use the __import__ function), and reload them when they change. Note that you will still have the issue that existing instances of classes will not automagically change to reflect the new class definition.
1
0
0
I currently have a python script that runs every few minutes and picks up "rules", in my case python classes, within files in a directory tree. for each class it can load it runs "execute()" and in this way lets me do useful things like monitor log files and so on. I'm now revisiting the script to make it self documenting and it strikes me that perhaps there is a neater way of picking up these ad hoc classes; maybe a framework or nice example somewhere. Can anyone suggest a neat solution?
Can someone recommend a pythonic approach to loading adhoc code?
1.2
0
0
134
9,994,397
2012-04-03T13:33:00.000
2
0
1
0
python,eclipse,pydev
9,995,341
3
false
0
0
While I don't know how to increase the delay, here's a throwing-the-baby-out-with-the-bathwater workaround: In Preferences/Pydev/Editor/Hover, uncheck Show docstrings?. Then you won't get any popups when hovering.
2
2
0
When moving the mouse cursor over the python source in Pydev/eclipse, a hint-window emerges with short documentation of the function or variable hovered over. While in itself this is a handy function, it is way to fast and causing me difficulties to position the cursor for inserting code. How can I increase the delay and so, reduced the number of hints?
pyDev-Eclipse: how to delay the hints
0.132549
0
0
195
9,994,397
2012-04-03T13:33:00.000
0
0
1
0
python,eclipse,pydev
10,009,926
3
false
0
0
This is a system wide setting. On Windows it can be modifying by editing registry entry HKEY_CURRENT_USER\Control Panel\Mouse\MouseHoverTime.
2
2
0
When moving the mouse cursor over the python source in Pydev/eclipse, a hint-window emerges with short documentation of the function or variable hovered over. While in itself this is a handy function, it is way to fast and causing me difficulties to position the cursor for inserting code. How can I increase the delay and so, reduced the number of hints?
pyDev-Eclipse: how to delay the hints
0
0
0
195
9,994,566
2012-04-03T13:43:00.000
4
0
1
0
python,multiprocessing,zeromq,gevent,pyzmq
10,001,944
2
false
0
0
Multiprocessing will clearly have much higher memory overhead but will utilize another core (and you don't have to worry about lack of pre-emption) so.. it depends on your needs. It's likely that multiple processes using gevent will get you the highest throughput / lowest latency.
2
4
0
Currently I am using zeromq with pub-sub pattern, I have single worker to publish and many(8) subscriber (all will subscribe) to same pattern. Now I tried multiprocessing to spawn subscribers it works. I am missing few messages. Why I am using multiprocessing is to handle each message as it arrives and process them, every second publisher publishes 10 - 100 messages. In this case it is advised use multiprocessing or gevent ?
Multiprocessing vs gevent
0.379949
0
0
2,824
9,994,566
2012-04-03T13:43:00.000
4
0
1
0
python,multiprocessing,zeromq,gevent,pyzmq
10,206,276
2
false
0
0
I am answering my own question I choose multiprocessing over gevent Server had 8 cores Parallelism was needed Choose ZMQ over multiprocessing queue or gevent queue.
2
4
0
Currently I am using zeromq with pub-sub pattern, I have single worker to publish and many(8) subscriber (all will subscribe) to same pattern. Now I tried multiprocessing to spawn subscribers it works. I am missing few messages. Why I am using multiprocessing is to handle each message as it arrives and process them, every second publisher publishes 10 - 100 messages. In this case it is advised use multiprocessing or gevent ?
Multiprocessing vs gevent
0.379949
0
0
2,824
9,995,041
2012-04-03T14:10:00.000
1
0
0
0
python,django
9,995,337
3
false
1
0
I certainly use class methods, and I have found that where there are similar operations to be performed on classes, it is possible (and easy) to factor the classmethods into base classes (use the self parameter of your class method to write generic code). Probably the best way to manage broken-up views, etc is to replace each file you want to break up with its own package, and put whatever you need to (if anything) into that package's __init__.py module.
2
4
0
I have a Django project which is getting more and more complex. I started off with the traditional files: models, views, and forms.py. The issue I have right now is that those files are getting bigger and bigger and I'd like to break them into manageable parts. What are the best practices around that? In addition, I am wondering if it is best practice to add class method to a model in Django? For instance, I have a Vote class on which I would like to add methods to get the number of votes for a specific user, content, etc?
How to structure complex Django project?
0.066568
0
0
1,093
9,995,041
2012-04-03T14:10:00.000
2
0
0
0
python,django
9,997,876
3
true
1
0
I find refactoring can really help. Are there a lot of similar views that just have different templates or querysets? Make a more generic view that accepts multiple template names, records, etc. Anything that requires extensive calculations gets moved to a utils.py in the same directory. Class methods are for actions that affect a single record; managers are for dealing with filtering records or creating a record. If you're already taking the step of making separate models, views, etc. folders and breaking views and models into separate files, that suggests to me that you could separate them out into separate apps. I like that as an option much better.
2
4
0
I have a Django project which is getting more and more complex. I started off with the traditional files: models, views, and forms.py. The issue I have right now is that those files are getting bigger and bigger and I'd like to break them into manageable parts. What are the best practices around that? In addition, I am wondering if it is best practice to add class method to a model in Django? For instance, I have a Vote class on which I would like to add methods to get the number of votes for a specific user, content, etc?
How to structure complex Django project?
1.2
0
0
1,093
9,996,095
2012-04-03T15:05:00.000
0
0
1
0
python
14,462,682
5
false
0
0
If in case you can use sed then you can do this way from command line sed -re 's/,*$//g' temp.csv
1
4
0
I've got a csv file and whenever i access the elements it gets me aapl,2001-12-4,,,,, The commas at the end is causing my functions to not work properly for my other application. How can I remove this in order to get rid of any additional commas after elements? for example the above after correction would be aaple,2001-12-4 anything will help, thanks so much. m
Get rid of extra commas from excel file with python
0
0
0
3,966
9,996,105
2012-04-03T15:06:00.000
0
1
0
0
python,python-imaging-library,python-c-extension
9,996,422
2
false
0
1
C-level bindings for PIL are available, but there is very little documentation for them. You will need to consult the source for usage information.
1
4
0
What is the most efficient way in terms of speed to access the pixel data of a PIL image from a C extension? I only need read-only access to it, if that makes a difference.
Accessing PIL image data from C extension
0
0
0
456
9,996,435
2012-04-03T15:23:00.000
1
1
0
0
c#,.net,python,user-interface
9,999,447
2
true
0
1
It sounds like you might be looking for a test automation tool, to script GUI events. I looked into using Ranorex for that a while back, and it looked very capable, but it was too expensive and overkill for my needs.
1
0
0
I am writing my own GUI with .NET (C#) and I want to use a python script to click buttons for me automatically and read from text boxes etc. I've tried the Google searches but nothing really helpful. Is there a library that I need to download for .NET or is there a module in python that will do what i"m looking for. I'm sure it can be done, I just don't know where yo start
Python script to control GUI?
1.2
0
0
793
9,998,274
2012-04-03T17:23:00.000
5
0
0
0
python,tkinter,keyboardinterrupt
10,067,034
1
true
0
1
from the newsgroups: I'm using Python 1.5 under Redhat Linux 5.0. I'm trying to figure out the best way to trap a SIGINT (or Ctrl-C) when using tkinter. To illustrate the problem I have, do the following ... -- Build Python-1.5 with tkinter enabled. -- Go into the Demo/tkinter/guido directory under the Python-1.5 build tree. -- Type "python imageview.py image-file", where "image-file" is the full pathname of a displayable image. -- Once the image pops up, make sure that the window focus is held by the xterm window from which the "python ..." command was just now invoked. -- Hit Ctrl-C. At this point, nothing happens. The Ctrl-C seems to be ignored. But now ... -- Without hitting any more keys on the keyboard, set the window focus to the displayed image window. As soon as that window gets the focus, the Ctrl-C takes effect. My question is this: is there any way to restructure the "imageview.py" program so that it will respond to SIGINT (Ctrl-C) immediately, without having to set the window focus to the displayed image first? Thanks in advance for any help you folks can give me. ---- What you're seeing is caused by the way signal handlers are handled. You're stuck in the Tcl/Tk main loop, and signal handlers are only handled by the Python interpreter. A quick workaround is to use after() to schedule a dummy function to be called once a second or so -- this will make it appear that your signal is handled in a timely manner. --Guido van Rossum
1
6
0
I have a GUI application written with python+tkinter. In my workflow, I generally start the gui from the commandline, do some things in the gui and then I find myself navigating to other terminal windows to do some work. Inevitably, I want to shut down the GUI at some point, and out of habit I often just navigate to the terminal that started the GUI and send a KeyboardInterrupt (Ctrl-c). However, This interrupt is not recieved until I raise the GUI window in the Window manager. Does anyone know why this happens? If the gui is started in a single function, is there a simple workaround -- multiprocessing maybe?
tkinter keyboard interrupt isn't handled until tkinter frame is raised
1.2
0
0
2,414
9,998,488
2012-04-03T17:38:00.000
0
0
1
0
python
9,998,527
5
false
0
0
This is because 'string' is a string. So is 'list' To get a similar result for lists, try help([])
2
1
0
When I type help('string') in the python interpreter I get information about the string class. There,upper() is indicated as a function. Yet I can only call it as a method like "hi".upper() instead of upper("hi"). So one could assume that any method will be indicated as a function in the docstrings of the built in modules. Yet when I do help('list') , methods of the list class are indicated as methods in the docstrings!! Why is this so? Only because the person who wrote the doctrings was inconsistent or that different people wrote it? Or do these methods(the ones called 'functions' versus the ones called 'methods' in the docstrings) actually have different properties?
Inconsistency in python help('string') versus help(list)?
0
0
0
427
9,998,488
2012-04-03T17:38:00.000
2
0
1
0
python
9,998,583
5
false
0
0
You mean to do help('str'), not help('string'). str is a type, string is a module providing functions for working with strings.
2
1
0
When I type help('string') in the python interpreter I get information about the string class. There,upper() is indicated as a function. Yet I can only call it as a method like "hi".upper() instead of upper("hi"). So one could assume that any method will be indicated as a function in the docstrings of the built in modules. Yet when I do help('list') , methods of the list class are indicated as methods in the docstrings!! Why is this so? Only because the person who wrote the doctrings was inconsistent or that different people wrote it? Or do these methods(the ones called 'functions' versus the ones called 'methods' in the docstrings) actually have different properties?
Inconsistency in python help('string') versus help(list)?
0.07983
0
0
427
9,999,005
2012-04-03T18:16:00.000
2
0
0
0
python,django
9,999,509
2
false
1
0
There's no such thing as a "global variable" in Python that is available from everywhere. You need to import all names before you can use them. Even if you did this, though, it wouldn't actually work on production. Not only is there no command that you run to start up the production server (it's done automatically by Apache or whatever server software you're using), the server usually runs in multiple processes, so the variable would have to be set in each of them. You should use a setting, as dcrosta suggests.
1
0
0
I have this kind of setup : Overridden BaseRunserverCommand that adds another option (--token) that would get a string token. Store it in the app called "vault" as a global variable Then continue executing the BaseRunserverCommand Now later when I try to get the value of this global variable after the server started, I am unable to see the value. Is this going out of scope? How to store this one time token that is entered before the django starts?
Creating an in memory constant when django starts
0.197375
0
0
92
9,999,618
2012-04-03T18:59:00.000
10
1
0
0
python,maven
9,999,984
4
true
1
0
It is the good news: you do not need any tool. You can organise your source code in any way you want. Let recap why we need tools in the java world: In java you want to generate directories upfront because the namespace system dictates that each class must live in one file in a directory structure that reflects that package hierarchy. As a consequence you have a deep folder structure. Maven enforces an additional set of convention for file location. You want to have tools to automate this. Secondly, different artefacts require use of different goals and even additional maven projects (e.g. a ear project requires a few jars and war artefacts). There are so many files to create you want to have tools to automate this. The complexity makes tools like mvn archetype:generate not just helpful. It is almost indispensable. In python land, we just do not have these complexity in the language. If my project is small, I can put all my classes and functions in a single file (if it makes sense) If my project is of a bigger size (LOC or team size), it makes sense to group .py files into modules in whatever way makes sense to you and your peers. At the end of the days, it is about striking a balance between ease of maintenance and readability.
1
16
0
Are there any tools which generate a project layout for python specific projects, much similar to what maven accomplishes with mvn archetype:generate for java projects.
Project structure for python projects with maven
1.2
0
0
15,040
10,000,256
2012-04-03T19:46:00.000
2
0
0
0
python,sql-server,py2exe,pyodbc
10,001,004
2
false
0
0
In the last project I worked on, I found that DRIVER={SQL Server};SERVER=SERVERNAME;DATABASE=DBName is sufficient to initiate a db connection in trusted mode. If it still does not work, it is probably either 1) the account DEEPTHOUGHT on mssql server is not set up properly. 2) the runAs in the service is not set up properly (why error message mentions 'ComputerName' instead of 'DEEPTHOUGHT'?)
1
4
0
Ok so I have a script that connects to a mssql db and i need to run as a service which I have already accomplished but when I run it as a service it overrides my credentials that I have put in when i connect to the db with the ad computer account. It runs perfect when i run it on its own and not as a service. My Connection String is: 'DRIVER={SQL Server};SERVER=MyServer;DATABASE=MyDB;UID=DOMAIN\myusername;PWD=A;Trusted_Connection=True' The Error is: Error: ('28000', "[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'DOMAIN\COMPUTERNAME') Any Advice?
Failed to Login as 'Domain\ComputerName' pyodbc with py2exe
0.197375
1
0
7,735
10,000,504
2012-04-03T20:03:00.000
0
0
0
0
python,django,sorl-thumbnail
10,002,629
2
false
1
0
I'd recommend you look at the source for sorl-thumbnail. Really all sorl-thumbnail is, is a wrapper around PIL (python imaging library). Although I'm sure you can figure out a way possibly to uncouple sorl-thumbnail from django it's going to be nontrivial. That said if you say set it up as a management command (with the full django environment as a result), you'd be able to use the low level api as documented in the sorl-thumbnail docs. That said you probably will be better off just figuring out how sorl-thumbnail interfaces with PIL and reproducing that part of the code in a decoupled manner since you will have to do additional post processing (likely with PIL again) that sorl-thumbnail can't do anyway. Also bear in mind on all of this, I'm not sure what your intention is...none of this is something you could set up to be run on off of a webserver. You can't run a python script on a client's computer who is connecting to a django server, that's just beyond impossible. However, generating a python program to produce watermarked thumbnails is completely possible if you're just handing it out to some coworkers or something. If you indeed are trying to have arbitrary people visit your site and upload watermarked/thumbnailed files to you via a web interface...well then you'll want to start some serious javascript studying.
1
0
0
In my case I have an opportunity to generate image thumbnails and do some post-processing before they are uploaded to a server (Amazon S3) on administrators computer. I know that sorl checks if thumbnail exists before generating it, but utilize kinda complicated naming scheme, so I hope there is a way to access sorl directly from my script. Official documentation says nothing about using sorl-thumbnail standalone, any suggestions?
How to use sorl-thumbnail without django?
0
0
0
350
10,000,524
2012-04-03T20:04:00.000
1
1
1
0
c++,parallel-processing,boost-python,cpython
10,002,004
1
false
0
1
As of today, you cannot avoid GIL interactions when using python threads in the same process. You may want to have a look at multiprocessing module which is meant to easily spawn Python processes, thus not interacting with GIL. Another option is to explicitly release the GIL when its not needed in your wrapped C/C++ functions. This can be done using PyEval_SaveThread and PyEval_RestoreThread functions.
1
2
0
I'm having a problem with my (game) application, which is using Boost.Python, when it comes to the scripting part. I have a client thread and a server thread that runs in the same process if you do not connect to an external server. This is where my problems arise: It seems like the Python interpreter can't execute scripts in the client thread parallel with scripts in the server thread, as it causes the application to crash. So my question is: Is there any possibility to run two (or more) scripts parallel in the Python interpreter? I have been searching all day and found a lot of information regarding Py_NewInterpreter, but this does not solve my problem as it uses GIL, I don't want the interpreter to lock other scripts from executing as it will cause lag on the client and/or the server side.
Running two python scripts parallel with boost::python
0.197375
0
0
624
10,001,529
2012-04-03T21:17:00.000
0
0
1
0
python,pdf
10,004,090
1
true
0
0
from the command line:python /path/to/pdf2txt.py -o text.txt /path/to/yourpdf.pdf You can then just take the text file it makes and use for line in file: If you want to be efficient you would have to change pdf2txt.py, and have outfp be a python iostring, which would avoid the making a file and then reading from it.
1
0
0
How can I get the content of pdf file line by line in python? I have searched in stackoverflow but could not find any good answer. Notes: pyPdf gives assertion erro, if possible something with slate and pdfminer.
python pdf line by line
1.2
0
0
472
10,002,209
2012-04-03T22:13:00.000
2
0
0
1
python,google-app-engine,authentication
10,023,490
1
true
1
0
User.federated_identity() "Returns the user's OpenID identifier.", which is unique by definition (it's a URL that uniquely identifies the user).
1
2
0
I need a unique datastore key for users authenticated via openid with the python 2.7 runtime for the google apps engine. Should I use User.federated_identity() or User.federated_provider() + User.federated_identity()? In other words is User.federated_identity() unique for ALL providers or just one specific provider?
Generating a unique data store key from a federated identity
1.2
1
0
194
10,002,771
2012-04-03T23:09:00.000
2
1
0
0
python,django,ssh
10,003,264
1
false
1
0
You're close. The problem here is probably that your web server runs as a non-privileged user (NOT root), like www or www-data or nobody (depending on your operating system). While that user can probably run the SSH binary, when doing so as nobody, it probably doesn't have a home directory, can't find your .ssh directory, and can't find the key file (.ssh/id_rsa for example) that it needs to use for authentication. You have a number of options. Make your private key available to the web server software, then launch ssh with the -i option to select an identity file. Or do this in an SSH config file that you specify with the -F option. Or launch ssh using sudo, and give your web server software the ability to run ssh as some other (shell) user. I can't provide a more specific answer because you haven't provided specifics in your question. Operating system, sample code, etc. Hope this helps. Oh, and you should also consider NOT doing this, and finding some other solution. A web application, even an internal one, that has SSH access to your firewall? Sounds like a recipe for eventual disaster to me. :-)
1
0
0
I acquired a python script that will either telnet to some equipment, or if the equipment is in a lab, ssh to a firewall machine and then it will telnet to the equipment, and run a command, returning the output for more processing. I took this script and tied it into a Django web app so that I could, from a browser, fill out a form with the target system info and have it display the results. If I start up this web app from the command line, and then access it from the browser (python manage.py app), everything works fine. However, if I set this up to run in "production" mode, using a virtual host with Apache, the SSH fails. I suspect that this is running under root or some web account and cannot SSH to the firewall. Can someone suggest how I get this to work? I don't have any privileges on the firewall machine, so I can't setup SSH to run under some web account. Would I need to collect username and password from the user, in the case where SSH is used, and then pass it to ssh, or are there other ways to get the telnet info and command through to the equipment?
need to ssh to remote machine from web page with python/django
0.379949
0
0
2,644
10,003,152
2012-04-03T23:57:00.000
0
1
0
0
python,matplotlib
10,003,436
1
false
0
0
Did you try to remove the pyc file ? It may happen as the pyc file exists that PyLab keeps reading it without reloading the file.
1
0
0
I have a simple question. I am in the process of debugging some code. I am using Enthought Python, with the "PyLab" program. I edit my code using gEdit. I am using Ubuntu 10.04.4 LTS. I use "run myfile.py" to run the program. Then I test myfile(somearguments), and see where the bugs are. However, when I make changes to the code, using "run myfile.py" again does not properly update what Python/PyLab on the changes to my code. The result is that I will get error messages back pointing to lines that have no errors, and don't even have the "trouble" text in them anymore. I tried using import and reload as well, but that didn't work. How do I get Python/PyLab to see the new changes to my code? The only option I have for now is to fix the bug and then restart PyLab to confirm the fix. Thanks!
Python "run" and "reload" not showing the changes to my code
0
0
0
233
10,003,232
2012-04-04T00:08:00.000
6
0
1
0
python,matrix,linear-algebra
10,003,296
2
false
0
0
The rule of Sarrus is only a mnemonic for solving 3x3 determinants, and won't be as helpful moving beyond that size. You should investigate the Leibniz formula for calculating the determinant of an arbitrarily large square matrix. The nice thing about this formula is that the determinant of an n*n matrix is that it can be determined in terms of a combination of the determinants of some of its (n-1)*(n-1) sub-matrices, which lends itself nicely to a recursive function solution. If you can understand the algorithm behind the Leibniz formula, and you have worked with recursive functions before, it will be straightforward to translate this in to code (Python, or otherwise), and then you can find the determinant of 4x4 matrices and beyond!
1
3
1
I'm making a small matrix operations library as a programming challenge to myself(and for the purpose of learning to code with Python), and I've come upon the task of calculating the determinant of 2x2, 3x3 and 4x4 matrices. As far as my understanding of linear algebra goes, I need to implement the Rule of Sarrus in order to do the first 2, but I don't know how to tackle this Pythonically or for matrices of larger size. Any hints, tips or guides would be much appreciated.
Python determinant calculation(without the use of external libraries)
1
0
0
3,244
10,004,987
2012-04-04T04:34:00.000
3
0
1
0
python,comparison,tuples
10,005,224
3
false
0
0
As Dougal says in his comment, is tests that the two things you are comparing are the in the same place in memory. For things like numbers, strings, booleans and the empty tuple, Python reuses objects by default (interning) so is will often produce the same behaviour as ==. This also means that you can get some performance gains by comparing memory pointers rather than more complex datatypes like strings. For other things such as the tuple in your case (even though they are immutable), or lists and even the empty list [], Python will create a new object in a different memory location and is won't work the same way as == If you're trying to compare the two tuples by value, == would be the better comparison.
1
12
0
Why is () is () true, yet (0,) is (0,) is false? I thought they would be the same object. However, I'm apparently missing something.
The Python "is" statement and tuples
0.197375
0
0
445
10,006,017
2012-04-04T06:34:00.000
2
0
1
0
python,logging
10,023,080
2
false
0
0
I think there is no magic scanning here. Try to test it this way in a separate test directory: test/main.py: import logging logging.info('test') test/any.py: import logging logging.basicConfig(filename='test.log', level=logging.INFO) python main.py Result: NO test.log file. Now let's update the test: test/main.py: import logging import any logging.info('test') python main.py Result: new test.log file with INFO:root:test string inside. So I guess that any.py in your case is imported somehow, despite your expectations. You may find the way any.py is imported easily, just add few lines there: test/any.py: from traceback import print_stack print_stack() ... python main.py Result: File "main.py", line 2, in import any File "any.py", line 2, in print_stack() This stack shows that any.py is imported from main.py. I hope you will find where it is imported from in your case.
1
2
0
I used to Python logging, it works fine. The logging.basicConfig(...) set in one module (a some.py file), then we can use logging every where. Obviously, logging is global. The question is how logging find it's settings, when we not call the module where basicConfig(...) appeared (in some.py file )? Is logging scan all the packages? Even the logging.basicConfig(...) put into an any.py and the module (any.py) never get imported, or not used anywhere, the logging setting take effect!
How python logging get it's configuration
0.197375
0
0
727
10,006,467
2012-04-04T07:11:00.000
1
0
1
0
python,nlp,nltk
10,054,525
2
true
0
0
You don't need to input the files yourself or to provide words and sents methods. Read in your corpus with PlaintextCorpusReader, and it will provide those for you. The corpus reader constructor accepts arguments for the path and filename pattern of the files, and for the input encoding (be sure to specify it). The constructor also has optional arguments for the sentence and word tokenization functions, so you can pass it your own method to break up the text into sentences. If word and sentence detection is really simple, i.e., if the | character has other uses, you can configure a tokenization function from the nltk's RegexpTokenizer family, or you can write your own from scratch. (Before you write your own, study the docs and code or write a stub to find out what kind of input it's called with.) If recognizing sentence boundaries is non-trivial, you can later figure out how to train the nltk's PunktSentenceTokenizer, which uses an unsupervized statistical algorithm to learn which uses of the sentence terminator actually end a sentence. If the configuration of your corpus reader is fairly complex, you may find it useful to create a class that specializes PlaintextCorpusReader. But much of the time that's not necessary. Take a look at the NLTK code to see how the gutenberg corpus is implemented: It's just a PlainTextCorpusReader instance with appropriate arguments for the constructor.
1
0
1
I have hundreds of files containing text I want to use with NLTK. Here is one such file: বে,বচা ইয়াণ্ঠা,র্চা ঢার্বিত তোখাটহ নতুন, অ প্রবঃাশিত। তবে ' এ বং মুশায়েরা ' পত্রিব্যায় প্রকাশিত তিনটি লেখাই বইযে সংব্যজান ব্যরার জনা বিশেষভাবে পরিবর্ধিত। পাচ দাপনিকেব ড:বন নিয়ে এই বই তৈরি বাবার পরিব্যল্পনাও ম্ভ্রাসুনতন সামন্তেরই। তার আর তার সহকারীদেব নিষ্ঠা ছাডা অল্প সময়ে এই বই প্রব্যাশিত হতে পারত না।,তাঁদের সকলকে আমাধ নমস্কার জানাই। বতাব্যাতা শ্রাবন্তা জ্জাণ্ণিক জানুয়ারি ২ ণ্ট ণ্ট ৮ Total characters: 378 Note that each line does not contain a new sentence. Rather, the sentence terminator - the equivalent of the period in English - is the '।' symbol. Could someone please help me create my corpus? If imported into a variable MyData, I would need to access MyData.words() and MyData.sents(). Also, the last line should not appear in the corpus (it merely contains a character count). Please note that I will need to run operations on data from all the files at once. Thanks in advance!
Creating a corpus from data in a custom format
1.2
0
0
272
10,009,660
2012-04-04T10:53:00.000
9
0
0
1
python,installation,py2exe
10,009,715
2
false
0
0
Py2exe has to run on Windows, you can not run it in Linux. (Maybe wine can help, but I'm not sure)
1
9
0
I downloaded the actual py2exe package. But I've no idea how to get it in my system. I mean I can follow the tutorial a 100% but I can't find anything how to install py2exe to my kubuntu 11.10. I also can't find a py2exe.py which I could include to my workingfolder. Could some please help me the project has to be finish till tomorrow? Thanks for your help cheers, Chris
How to install the py2exe modul in Linux
1
0
0
23,189
10,012,741
2012-04-04T14:04:00.000
1
0
1
0
python,converter,python-sphinx,docstring,epydoc
13,075,229
4
false
0
0
In theory you could write a Sphinx extension which would catch whatever event gets fired when a docstring gets read (source_read, maybe?) and translate the docstrings on the fly. I say in theory because: I've been meaning to write such a thing for a very long time, but haven't managed to get around to it yet. Translating stuff like this is always harder than it seems. You could also probably try just replacing all the docstrings in your code with a similar translator outside of Sphinx, perhaps using the ast module or something similar.
1
10
0
I've got a project which I documented using epydoc. Now I'm trying to switch to sphinx. I formatted all my docstrings for epydocs, using B{}, L{} etc for bolding, linking and the like, and using @param, @return, @raise etc to explain input, output, exceptions and the likes. So now that I'm switching to sphinx it loses all these features. Is there an automated way to convert docstrings formatted for epydocs to docstrings formatted for sphinx?
Automated way to switch from epydoc's docstring formatting to sphinx docstring formatting?
0.049958
0
0
2,578
10,012,968
2012-04-04T14:16:00.000
4
0
1
0
python,optimization,parallel-processing
10,013,025
6
false
0
0
Starting independent Python processes is ideal. There will be no lock contentions between the processes, and the OS will schedule them to run concurrently. You may want to experiment to see what the ideal number of instances is - it may be more or less than the number of cores. There will be contention for the disk and cache memory, but on the other hand you may get one process to run while another is waiting for I/O.
2
11
0
We have a about 500GB of images in various directories we need to process. Each image is about 4MB in size and we have a python script to process each image one at a time (it reads metadata and stores it in a database). Each directory can take 1-4 hours to process depending on size. We have at our disposal a 2.2Ghz quad core processor and 16GB of RAM on a GNU/Linux OS. The current script is utilizing only one processor. What's the best way to take advantage of the other cores and RAM to process images faster? Will starting multiple Python processes to run the script take advantage of the other cores? Another option is to use something like Gearman or Beanstalk to farm out the work to other machines. I've taken a look at the multiprocessing library but not sure how I can utilize it.
Fastest way to process large files in Python
0.132549
0
0
4,472
10,012,968
2012-04-04T14:16:00.000
0
0
1
0
python,optimization,parallel-processing
10,014,037
6
false
0
0
If you are reading a large number of files and saving metadata to a database you program does not need more cores. Your process is likely IO bound not CPU bound. Using twisted with proper defereds and callbacks would likely outperform any solution that sought to enlist 4 cores.
2
11
0
We have a about 500GB of images in various directories we need to process. Each image is about 4MB in size and we have a python script to process each image one at a time (it reads metadata and stores it in a database). Each directory can take 1-4 hours to process depending on size. We have at our disposal a 2.2Ghz quad core processor and 16GB of RAM on a GNU/Linux OS. The current script is utilizing only one processor. What's the best way to take advantage of the other cores and RAM to process images faster? Will starting multiple Python processes to run the script take advantage of the other cores? Another option is to use something like Gearman or Beanstalk to farm out the work to other machines. I've taken a look at the multiprocessing library but not sure how I can utilize it.
Fastest way to process large files in Python
0
0
0
4,472
10,013,904
2012-04-04T15:06:00.000
2
0
0
0
python,user-interface
10,014,865
4
false
0
1
You think absolutely right. There are loads of python-based frameworks, just choose the right one: pyramid, pylons, django are the most popular and widely-used. I suggest you to outsource HTML/CSS slicing to some professional instead of doing it by yourself. You can face up quite a lot of browser-specific things, which will waste your time, but obvious for an experienced person.
2
5
0
I have a GUI project which I am about to start. GUI requirement is simple ( though not as simple as tkinter will suffice). So I need to use a GUI toolkit for python (which will be wxpython if I have to go for GUI). Now I am thinking, why cannot I use simple web-framework such as cherrypy or bottlepy (sorry, if I am not thinking right. I am newbie to server-side programming) and create html pages as my graphical interface and use DOM ( again,I guess, I am speaking right) rather than using wxpython to create the overall GUI. I can then, write all of my business logic and leave the rest to simple html rendering where I have to spend less time in formatting tables, creating buttons and forms and worrying about the sizers. My question is: Can somebody use web-server python package such as cherrypy or similar and get-away from using graphical toolkit? Is it really beneficial or am I thinking this thing upside down? The benefit I am expecting: I can use jquery to have many features which might take lot of time to create with wxpython or other GUI toolkit. For example, if I want to have autocomplete feature as similar to jquery, it is whole lot of different story in GUI toolkit like wxpython. And also, lot of drag and drop features are easy in html.
Using web-server to substitute for GUI in python
0.099668
0
0
6,264
10,013,904
2012-04-04T15:06:00.000
1
0
0
0
python,user-interface
10,013,987
4
false
0
1
No, you are thinking of this correctly. HTML/CSS is very simple it can lend to rapid development. Additionally python micro frameworks will make creating your business logic a breeze. This is a very straight forward sipmle route to take.
2
5
0
I have a GUI project which I am about to start. GUI requirement is simple ( though not as simple as tkinter will suffice). So I need to use a GUI toolkit for python (which will be wxpython if I have to go for GUI). Now I am thinking, why cannot I use simple web-framework such as cherrypy or bottlepy (sorry, if I am not thinking right. I am newbie to server-side programming) and create html pages as my graphical interface and use DOM ( again,I guess, I am speaking right) rather than using wxpython to create the overall GUI. I can then, write all of my business logic and leave the rest to simple html rendering where I have to spend less time in formatting tables, creating buttons and forms and worrying about the sizers. My question is: Can somebody use web-server python package such as cherrypy or similar and get-away from using graphical toolkit? Is it really beneficial or am I thinking this thing upside down? The benefit I am expecting: I can use jquery to have many features which might take lot of time to create with wxpython or other GUI toolkit. For example, if I want to have autocomplete feature as similar to jquery, it is whole lot of different story in GUI toolkit like wxpython. And also, lot of drag and drop features are easy in html.
Using web-server to substitute for GUI in python
0.049958
0
0
6,264
10,017,645
2012-04-04T19:06:00.000
1
1
0
0
python,database,django,apache,mod-wsgi
10,020,054
1
true
1
0
First up, look at daemon mode of mod_wsgi and don't use embedded mode as then you can control separate to Apache child processes the number of Python WSGI application processes. Secondly, you would be better off putting the memory hungry bits in a separate backend process. You might use XML-RPC or other message queueing system to communicate with the backend processes, or even perhaps see if you can use Celery in some way.
1
2
0
I'm writing a Oracle of Bacon type website that involves a breadth first search on a very large directed graph (>5 million nodes with an average of perhaps 30 outbound edges each). This is also essentially all the site will do, aside from display a few mostly text pages (how it works, contact info, etc.). I currently have a test implementation running in Python, but even using Python arrays to efficiently represent the data, it takes >1.5gb of RAM to hold the whole thing. Clearly Python is the wrong language for a low-level algorithmic problem like this, so I plan to rewrite most of it in C using the Python/C bindings. I estimate that this'll take about 300 mb of RAM. Based on my current configuration, this will run through mod_wsgi in apache 2.2.14, which is set to use mpm_worker_module. Each child apache server will then load up the whole python setup (which loads the C extension) thus using 300 mb, and I only have 4gb of RAM. This'll take time to load and it seems like it'd potentially keep the number of server instances lower than it could otherwise be. If I understand correctly, data-heavy (and not client-interaction-heavy) tasks like this would typically get divorced from the server by setting up an SQL database or something of the sort that all the server processes could then query. But I don't know of a database framework that'd fit my needs. So, how to proceed? Is it worth trying to set up a database divorced from the webserver, or in some other way move the application a step farther out than mod_wsgi, in order to maybe get a few more server instances running? If so, how could this be done? My first impression is that the database, and not the server, is always going to be the limiting factor. It looks like the typical Apache mpm_worker_module configuration has ServerLimit 16 anyways, so I'd probably only get a few more servers. And if I did divorce the database from the server I'd have to have some way to run multiple instances of the database as well (I already know that just one probably won't cut it for the traffic levels I want to support) and make them play nice with the server. So I've perhaps mostly answered my own question, but this is a kind of odd situation so I figured it'd be worth seeing if anyone's got a firmer handle on it. Anything I'm missing? Does this implementation make sense? Thanks in advance! Technical details: it's a Django website that I'm going to serve using Apache 2.2.14 on Ubuntu 10.4.
Maximizing apache server instances with large mod_wsgi application
1.2
1
0
214
10,018,055
2012-04-04T19:35:00.000
0
0
0
0
python,django,mysql-python
10,192,810
1
false
1
0
I would think this would be more inline with setting a read_timeout on your front-facing webserver. Any number of reasons could exist to hold up your django app indefinitely. While you have found one specific case there could be many more (code errors, cache difficulties, etc).
1
2
0
I've been doing some HA testing of our database and in my simulation of server death I've found an issue. My test uses Django and does this: Connect to the database Do a query Pull out the network cord of the server Do another query At this point everything hangs indefinitely within the mysql_ping function. As far as my app is concerned it is connected to the database (because of the previous query), it's just that the server is taking a long time to respond... Does anyone know of any ways to handle this kind of situation? connect_timeout doesn't work as I'm already connected. read_timeout seems like a somewhat too blunt instrument (and I can't even get that working with Django anyway). Setting the default socket timeout also doesn't work (and would be vastly too blunt as this would affect all socket operations and not just MySQL). I'm seriously considering doing my queries within threads and using Thread.join(timeout) to perform the timeout. In theory, if I can do this timeout then reconnect logic should kick in and our automatic failover of the database should work perfectly (kill -9 on affected processes currently does the trick but is a bit manual!).
How can I detect total MySQL server death from Python?
0
1
0
181
10,018,767
2012-04-04T20:29:00.000
0
0
0
0
python,pygtk
10,057,082
1
false
0
1
If you want to display an image and allow the user to select and move parts of it, you best look for a ready-made image editing widget. GTK doesn't come with one. To roll your own you can use an image widget for display, but it doesn't care about the mouse, so you can place it inside an event box and connect to button and movement events. You'll have to handle all the drawing of rectangle, walking ants and floating cutout yourself in the pixbuf backing the image. It might be easier to start from scratch with an empty event box and draw even the image yourself.
1
0
0
What I'm wanting to do is create a selection tool (like what you see in most paint programs) using PyGtk. I've seen a previous question that asked something similar, but they already seemed to know what they were doing to make the selection itself. That user said he was using an eventbox, but I don't know how I would use that to accomplish what I am trying to do. How would the eventbox work with a selection? The algorithm for the rectangle isn't a problem at all, I just need to know what tools I should be using to actually select a part of a picture and be able to move it around. This is my first time using PyGtk, and I'm also fairly new to python itself, so any help would be great.
How do I create a canvas selection tool?
0
0
0
212
10,019,043
2012-04-04T20:50:00.000
1
0
1
0
python,exception,python-3.x,assert,software-design
10,038,223
2
false
0
0
assert statements are for things that you use while developing and debugging the code, not to guarantee critical API constraints. For your positive number example, test the value and raise ValueError with a useful error message if using a negative value within your code would have bad consequences. I tell people never to use assert statements. They are easy to write but yet they are so often inappropriate. assert statements also fall over when people write long ones and decide to use parentheses to make the statement and message span multiple lines... This generates a SyntaxWarning in modern Python about the tuple that the author inadvertently created by using (condition, message) on a non-function statement but it hasn't always done so. Another rule of thumb: If you ever see a unittest verifying that an AssertionError was raised, the code should not be using an assert. If you don't use assert statements none of these things will ever bite you.
1
2
0
The best practice seems to be to use assert for a condition that should never happen if the code is correct, and an exception for a condition that is a bit unusual but can happen (e.g., when memory runs out, or user input is invalid, or external connections are broken). I understand the rationale behind this practice as follows: assert will be disabled with -O interpreter flag. Conditions that may arise from external factors must not be allowed to be silently ignored, so assert there is inappropriate. OTOH, conditions that may only arise if my code is incorrect are hopefully eliminated through testing and debugging, so assert is fine. assert discourages the caller from handling the exception, since AssertionError is usually interpreted as "don't catch me, this is a catastrophic failure". Furthermore, it is too generic to catch. This is perfect when a bug is found; the typical handling for that would be to stop the execution and debug the code. It is not good if it's a common condition due to external reasons. Suppose I write some code where I ensure that a certain function argument is always positive. If I find it to be negative, clearly I made a mistake in the code. Hence, I am going to assert that the argument is positive. Later, someone finds this function useful in another application. They import it, and send all sorts of data to it. Now from the perspective of my function, receiving a negative value is actually quite likely; it is simply an invalid user input. Arguably, the assert is no longer appropriate, and should be replaced with an exception. Since almost any code could potentially be reused one day, often without my knowledge, this argument seems to say "never use assert; only use exceptions". Obviously, this is not an accepted practice. What am I missing? EDIT: To be more specific, let's say the function cannot handle a negative argument at all. So once the argument is negative, the function will do one of the following: raise an exception fail an assert continue execution, likely producing incorrect output I can see how it would be nice if negative arguments were caught by the caller. But if the calls to the function are interspersed in dozens of places around the code, it's arguably detrimental to the code clarity due to the numerous repetitions of the same check. (Not to mention, it could be forgotten by accident.)
Python assert statement and code reusability
0.099668
0
0
1,765
10,019,456
2012-04-04T21:22:00.000
2
0
1
0
python,sys
51,362,095
6
false
0
0
As per my understanding sys.stdout.flush() pushes out all the data that has been buffered to that point to a file object. While using stdout, data is stored in buffer memory (for some time or until the memory gets filled) before it gets written to terminal. Using flush() forces to empty the buffer and write to terminal even before buffer has empty space.
1
217
0
What does sys.stdout.flush() do?
Usage of sys.stdout.flush() method
0.066568
0
0
230,848
10,020,073
2012-04-04T22:18:00.000
0
0
0
0
django,ldap,django-authentication,python-ldap
10,024,636
1
true
1
0
For those that are interested, the solution was that there is a setting in the LDAP module called AUTH_LDAP_ALWAYS_UPDATE_USER which you need to set to False to make sure it doesn't update every time.
1
1
0
I have a Django app which uses LDAP as the authentication backend. I'm not sure whether it's the LDAP module or just Django itself but, if a user changes their email address, first name or last name and then logs out and back in again, the values revert to their original values (ie. the ones obtained from the LDAP record). Has anyone seen this kind of behaviour before and is there any way to prevent it? The problem I have is that the email addresses in the LDAP records are incorrect and need updating but I have no control over them. The only thing I can control is the Django user database.
User login overwrites user fields
1.2
0
0
80
10,020,389
2012-04-04T22:52:00.000
-1
0
0
1
winapi,windows-7,python-3.x,block,pywin32
28,282,261
1
false
0
0
write a while loop Into the while loop write the command to taskkill dwm.exe It's a poor solution, but the only one I know. Regards!
1
0
0
This might be a more difficult question since I don't even know how to do it outside of Python... I want to write a terminal program that completely locks up my PC until a password is entered. In the locked state no one should be able to do anything outside the terminal. In it, the user may rampage and write silly commands, but he should not be able to switch windows, click outside of it, open the task manager, open the menu with Ctrl + Alt Gr + Del and so on. While searching for a way to accomplish this I've thought of two approaches that Python is also able to do: Modifying the registry -> can disable task manager and some other functions, but not the app switcher neither the menu Task-killing explorer.exe and dwm.exe -> killing explorer.exe just removed the taskbar, killing dwm.exe seems like the right way, but as it's the window manager it automatically boots up itself again as soon as it gets killed I know this is a kind of weird question and doesn't contain any code snippet, but the front-end is no problem and as said I don't even got a working approach for the back-end.
Completely locking down Windows 7 using Python 3.2?
-0.197375
0
0
545
10,020,528
2012-04-04T23:08:00.000
0
0
0
0
python,sqlite,wxpython,wxwidgets
10,021,932
2
false
0
1
In different scenarios, the strategies will be different. The assumption is that you just use wxPython for presentation purpose, and you have a separate module/package dealing with the data. wxPython controls get data only from the data abstraction layer. Scenario I: load all the log data into the memory and use wx.listctrl or wx.listview to display the lines. Scenario II: fetch data from the database when the wx view is updated. In Scenario I, you just need to setup an variable to remember the position the UI has read up to, or even you can simply use list sliding if you load the logs as list. Automatically updating the view by scrolling down/up can be implemented in scenario I because all data has been loaded and no more sqlite db connection will be made. It will be a bad choice to implemented auto-updating by scrolling down/up in scenario II since there would be too many db operations - imagine you scrolling down very quickly expecting to get the 5000th line? In scenario II, you can setup a page size and use LIMIT/OFFSET to get the data set you want. You keep another variable for the offset number. With the variables page_size and offset, you can simply fetch the data and update the wx view. This scenario is especially good for limiting the memory use. I don't know how big your log is, but after all it is not a good idea to load all of it into the memory because a log keeps growing and you may also need to load other relatively large dataset at the same time.
1
1
0
I have a large data set (log data) that is stored in a SQLite3 database. I created a Python GUI using Wx.listctrl that displays that data from a query. It works fine for small amounts of data but obviously hangs on larger sets.. therefore I would like to implement one of two things: -paging were the first 5000 records are shown in the listctrl and then if a user clicks a button the next 5000 are shown .. so on and so on.. OR -as the user scrolls down the listctrl its constantly populating with new data.. How would I implement one of these concepts? Thanks in advance for the help!
Display large dataset from Sqlite database in Python wx
0
0
0
1,254
10,020,908
2012-04-04T23:55:00.000
0
0
0
0
python,ruby-on-rails,numpy
10,021,813
2
false
1
0
I assume that the Python part is a stack of back-end libraries/modules of scientific functions while the Ruby-on-Rail part is mostly as front-end. Then an relatively simple solution would be wrap those Python modules/libraries into services and let the Ruby-on-Rail-built front-end functions call those services. To build the Python services, you can use xmlrpc for simple implementation, or some sophisticated framework such as twisted for larger scale implementation. You can also created only one portal service that hosts all your Python modules/libraries, that would basically give you an application server that handles all the requests form the Ruby-on-Rails front-end. Using which strategy depends on the scale and complexity of your Python libraries/modules.
1
4
0
I'm a fan of using the right tool for the job. At my company, the data analysts (incl myself) primarily use Python because of the powerful scientific libraries; the web people downstairs use Ruby on Rails for building our own HR management webapp as well as maintaining our online presence. We would like to have the two teams working a little closer together allowing the development of scientific webapps but are unsure about how to proceed. We have significant investment in both technologies with a substantial codebase that we would need to continue to use. Are there any suggestions about the best way to integrate the two domains of scientific programming and web apps using the two separate languages?
Integrating scientific python into an existing Rails webapp
0
0
0
917
10,021,846
2012-04-05T02:21:00.000
0
0
0
0
python,django
10,022,609
2
false
1
0
If you put some data in request.session it automatically creates a record in django_session on process_response of session middleware. So if you put nothing in the session, and it stores only login data - then it will be number of logins (also by the same user - logount clears session data so it's being recreated if anyone logs in)
2
0
0
I am looking at my table for django_session and would like to know what this essentially means. If I have 100 session entries in the past hour, does that mean 100 people have logged in in the past hour? Or does it mean something else?
Interpreting session activity
0
0
0
56
10,021,846
2012-04-05T02:21:00.000
0
0
0
0
python,django
10,030,017
2
false
1
0
It means there are 100 unique visting during which the request.session got modified. The unique visiting is based on per-user-browser: a user who uses Firefox and then Chrome to access your site AND having request.session modified during the process will be identified as two or more visting. Normally, there is no modification upon request.session thus no session entry will be generated. The default login page sets test flag in request.session, thus session entry will be generated for visitor, no matter whether he can log in successfully . Also, if a visitor denies cookie, his every access to the login page would generate a session entry.
2
0
0
I am looking at my table for django_session and would like to know what this essentially means. If I have 100 session entries in the past hour, does that mean 100 people have logged in in the past hour? Or does it mean something else?
Interpreting session activity
0
0
0
56
10,023,418
2012-04-05T06:05:00.000
0
0
0
0
python
10,023,435
3
false
1
0
Examine the Content-Disposition header of the response to discover what the server wants you to call the file.
1
2
0
I am having a problem and not sure if this is possible at all, so if someone could point me in the right direction. I need to open a file from a webpage, open it in excel and save the file. The problem I am running into the file name on the website has a file name ( not an active link ) and then it will have a "download " button that is not specific to the file I need to download. So instead of the download button being "file1todaysdate", they are nothing that I could use from day to day. Is there a way I could locate file name then grab the file from the download icon? then save in excel? If not sorry for wasting time.
Python File Download
0
1
0
1,137
10,023,941
2012-04-05T06:57:00.000
0
0
0
0
python,web2py,web2py-modules
42,826,179
3
false
1
0
You should mention your directory name in environmental variable PYTHONPATH so that it will locate your directory. Hopes this will help you :)
2
0
0
I have to develop web2py app and have to use Facebook sdk in that. I have downloaded facebook sdk zip folder to my windows pc and extarct it and uploaded facebook.py module to my web2py application and using statement "from applications.modules.facebook import * " in controller/default.py and when i run the application its giving below error: No module named modules.facebook. when i browse to application directory, I found facebook.py inside modules folder so not able to find what is the problem. Please guide me to resolve it. Regards, Piks
Getting error No module named modules.facebook
0
0
0
9,533
10,023,941
2012-04-05T06:57:00.000
0
0
0
0
python,web2py,web2py-modules
10,024,541
3
false
1
0
What is the folder structure of the facebook sdk? If it facebook/ and facebook/__init__.py is a file within it, then you can import it using import facebook or from facebook import * from the directory where you have facebook folder. If you are importing it from within modules, then make sure that you have placed the facebook package in the modules directory of the application.
2
0
0
I have to develop web2py app and have to use Facebook sdk in that. I have downloaded facebook sdk zip folder to my windows pc and extarct it and uploaded facebook.py module to my web2py application and using statement "from applications.modules.facebook import * " in controller/default.py and when i run the application its giving below error: No module named modules.facebook. when i browse to application directory, I found facebook.py inside modules folder so not able to find what is the problem. Please guide me to resolve it. Regards, Piks
Getting error No module named modules.facebook
0
0
0
9,533
10,025,521
2012-04-05T08:53:00.000
1
0
1
0
python,list,python-3.x
10,026,199
3
false
0
0
As the other answers say you don't need to know and you shouldn't care. In general empty lists and dictionaries are just like any other list or dictionary: indeed since you can mutate an empty list/dictionary it may later become non-empty. However, the empty tuple is slightly different as in at least some implementations of Python it is a singleton value. It is exceedingly unlikely that this will ever matter to you, but there it is.
2
1
0
I am new to python programming, as per OOps Concepts memory will allocated for every Object, in python programming, how the memory is allocated for [ ], { }, ( ) objects without elements? Thanks Mukthayr
How is memory allocated for empty list, tuple, dictionary?
0.066568
0
0
577
10,025,521
2012-04-05T08:53:00.000
4
0
1
0
python,list,python-3.x
10,025,587
3
false
0
0
If you're worrying about memory allocation for empty elements in Python, you're doing it wrong. Python is a high-level language with automatic memory management. Unless you're trying to deal with huge amounts of data in a severely memory-restricted environment, you should not be thinking about this.
2
1
0
I am new to python programming, as per OOps Concepts memory will allocated for every Object, in python programming, how the memory is allocated for [ ], { }, ( ) objects without elements? Thanks Mukthayr
How is memory allocated for empty list, tuple, dictionary?
0.26052
0
0
577
10,028,006
2012-04-05T11:48:00.000
0
0
1
0
python,generator
10,028,242
3
false
0
0
I thinks there is an error in your code. As you can see, float() is a function, and the statement float(i.dist) -= float(base) means assigning to function call, so it will be a syntax error :)
2
0
0
a short question: is it possible to assign the result of a calculation within a generator expression to a referrer? Let's assume I have an expression like this: m = (float(i.dist) - float(base) for i in met_obj if str(i.code) != '90') i.dist is an attribute of an object which I want to chance. I tried: m = (float(i.dist) -= float(base) for i in met_obj if str(i.code) != '90') Or would I need to use a generator instead? Thanks! LarsVegas
Assign calculated value to variable within generator expression?
0
0
0
1,169
10,028,006
2012-04-05T11:48:00.000
0
0
1
0
python,generator
10,028,687
3
true
0
0
A short answer: no, it is not possible.
2
0
0
a short question: is it possible to assign the result of a calculation within a generator expression to a referrer? Let's assume I have an expression like this: m = (float(i.dist) - float(base) for i in met_obj if str(i.code) != '90') i.dist is an attribute of an object which I want to chance. I tried: m = (float(i.dist) -= float(base) for i in met_obj if str(i.code) != '90') Or would I need to use a generator instead? Thanks! LarsVegas
Assign calculated value to variable within generator expression?
1.2
0
0
1,169
10,029,190
2012-04-05T13:06:00.000
6
0
0
0
python,django,amazon-ec2,wsgi
10,029,391
1
true
1
0
Yes you can have as many different django sites as your server can handle! You can set up separate virtual hosts pointing to the appropriate wsgi for each site you want. Remember just because it is possible doesn't mean it's a good idea, keep in mind the resources each site is consuming.
1
2
0
I intend to have many python with django applications on my server, is it ok to have django with wsgi and many sites on the one server? thanks!
django multiple sites wsgi is enough?
1.2
0
0
191
10,029,355
2012-04-05T13:16:00.000
0
0
0
0
python,linux,firefox,gnu
10,029,542
1
true
0
0
You might have some luck with DBus, although I don't know if it is provided in a standard install.
1
1
0
I need to get the content of URL bar (of currently opened tab) of Firefox using Python. I've found few solutions for Windows (using libraries such as pywin32) but I need it for GNU/Linux (if available then multi-platform way is the most preferred, of course). I have also found ways doing it by installing add-on for Firefox but I want user to install only Python and (when it's needed) libraries for it [Python].
Python - How to get the Firefox's URL bar content in GNU/Linux?
1.2
0
1
283
10,029,641
2012-04-05T13:36:00.000
0
0
0
0
python,excel,xlrd
10,029,868
1
false
0
0
As per the link for your question,I have posted above, the author of xlrd says, 'The work is 'in-progress' but is not likely to be available soon as the focus of xlrd lies elsewhere". By this, I assume that there is nothing much you can do about it. Note: this is based on author's comment on Jan, 2011.
1
2
0
I am trying to do a parser, that reads several excel files. I need values usually at the bottom of a row where you find a sum of all upper elements. So the cell value is actually "=sum()" or "A5*0.5" lets say... To a user that opens this file with excel it appears like a number, which is fine. But if I try to read this value with ws.cell(x, y).value I do not get anything. So my question is how to read this kind of fields with xlrd, if it is possible to read it like ws.cell(x, y).value or something similar? thanks
how to read formulas with xlrd
0
1
0
2,953
10,029,823
2012-04-05T13:47:00.000
3
0
1
1
python,path,directory,java
10,029,856
1
true
0
0
You can check for JAVA_HOME or JDK_HOME system variables. But there is no guarantee that there are no other JDKs installed. You have to be more specific what you are willing to achieve.
1
0
0
I'm currently writing a program in Python, and I would like to determine the path to the JDK install directory if it's on the system. Is there a way of doing this in Python? If not, is there a way of doing it in Java (or another language)? If it is the latter, I could open a subprocess from within Python to obtain it. Thanks.
Determine a JDK install directory through Python
1.2
0
0
970
10,031,427
2012-04-05T15:22:00.000
5
1
1
0
python,python-idle
10,031,501
1
true
0
0
The reason why this is sensible with LISP is that every LISP programs is just a bunch of macros and functions and the s-expressions can be formatted automatically into a nice representation. This isn't the case in Python, where you have more complex syntax (significant whitespace, decorators, lots of control structures, different types of string literals, ...) and more semantic elements (classes, functions, top-level code, ...), so this approach will not work very well here. The resulting code would get really messy for even the smallest of projects and the resulting code would still require a lot of "post-processing", somewhat annihilating the speed of development advantage. Instead, you can just write the code in a good text editor and Use built-in functionality to integrate it with the REPL (EMACS and Vim have good support for this kind of stuff) or load it into REPL using execfile, which will give you the comfort of good text editing and the interactivity of the prompt. along with the program, write a suite of unit tests. This is to be recommended for any non-trivial piece of software and automates the testing of your code, so you'll have to spend less time in an interactive prompt, manually checking if a function works correctly. You could also grab a more fully-featured IDE that supports code evaluation and full-blown debugging (PyDev is an example here, thanks to sr2222).
1
3
0
I'm not sure if I worded the subject correctly but essentially I'm curious if someone can develop code in the Python IDLE, or a similar tool, and then through some command spit out the current code in memory. I believe I did this previously when going through a Lisp book and recall it being a very different approach than the usual re-running of static files. Any suggestions as to how to do this or something similar? Thanks UPDATE I ended up using a combination of the IDLE using execfile and reload commands, while editing code in a separate editor (eclipse/pydev). I changed my "main" file so that nothing executes immediately when execfile is called on it. Code in the main file and modules imported are loaded into the current scope/stack so as I'm writing new code or an error occurs I can test directly in the IDLE command line. Once I have found the problem or way forward I then update code in editor, run reload(module) for updated modules, then execfile(path) on the main file.
Can a python IDLE be used for iterative/in-memory development?
1.2
0
0
199
10,032,077
2012-04-05T16:07:00.000
2
0
0
0
python,django
10,033,919
2
false
1
0
Have you left any debug prints in your view? That will cause a conversion to the console's encoding, which may be ascii causing this error.
2
2
0
Sometimes I m getting unicode errors like below in my django site when user submit form data. "'ascii' codec can't encode character u'\u2014' in position 109: ordinal not in range(128)" How can i reproduce the unicode error in my system Many Thanks.
reproduce unicode error in django
0.197375
0
0
309