python

Design question on Python network programming

I'm currently writing a project in Python which has a client and a server part. I have troubles with the network communication, so I need to explain some things... The client mainly does operations the server tells him to and sends the results of the operations back to the server. I need a way to communicate bidirectional on a TCP socke...

Using data from a specific class in python

storage = [] ... after running program storage = [ <main.Record instance at 0x032E8530> ] inside the instance of Record are: "Model No." "Standard: Part Number" "Standard: Issue Date" "Date of Declaration" "Declaration Document Number" Question: How do I use specific data from within the Record? ...

learning python - point to keep in mind w.r.t idioms!

I've been an avid learner of the Python language for quite some time. Having more than 6 years of Java[professional] experience, coupled with a bit of C++ [hobby] experience - it's fair to say my perspective is deeply entrenched in the idioms brought forth by such statically typed, strongly bound languages. In short - i could say the old...

How to use Scrapy

Hello, I would like to know how can I start a crawler based on Scrapy. I installed the tool via apt-get install and I tried to run an example: /usr/share/doc/scrapy/examples/googledir/googledir$ scrapy list directory.google.com /usr/share/doc/scrapy/examples/googledir/googledir$ scrapy crawl I hacked the code from spiders/google_di...

Pythonic way to perform a large case/switch

I'm pretty sure this is a really fundamental concept in Python, I'd love it if someone could help me understand how to do the following in a pythonic/clean way. I'm really new to coding so I will just show an example. I think it will be obvious what I am trying to do. for textLine in textLines: foo = re.match('[1-100]', thing) i...

Django, where to import your modules

I always thought it was OK to just import all of your modules at the top of a view file. Then if you ever change a model name you can just edit the import at the top and not go digging through every view function that you need it imported in. Well, I just ran into an instance where I had imported a model at the top of a view file, an...

How can I selectively mask arbitrary data being sent over an insecure link?

I'm using an offsite error logging package for my python web application. When I send an error I include the contents of (among other things) the POST variable and some template data. Some of this data must not be sent to the error logging service (passwords, some other template data). How can I take a payload that consists of a mix of ...

Python3 decorating conditionally?

Is it possible to decorate a function based on a condition? a'la: if she.weight() == duck.weight(): @burn def witch(): pass I'm just wondering if logic could be used (when witch is called?) to figure out whether or not to decorate witch with @burn? If not, is it possible to create a condition within the decorator to the sam...

How do I generate a connection reset programatically?

Hi, I'm sure you've seen the "the connection was reset" message displayed when trying to browse web pages. (The text is from Firefox, other browsers differ.) I need to generate that message/error/condition on demand, to test workarounds. So, how do I generate that condition programmatically? (How to generate a TCP RST from PHP -- or...

PyPi issues - Upload failed (401): You must be identified to edit package information

Im encountering a problem with pypi Similar to this one: http://stackoverflow.com/questions/1569315/setup-py-upload-is-failing-with-upload-failed-401-you-must-be-identified-to Except that im running windows and the mentioned solution page is down. Anyone knows how to work around this? Im using python 2.5 python setup.py sdist register ...

Write conditions based on a list

I'm writing an if statement in Python with a lot of OR conditions. Is there an elegant way to do this with a list, within in the condition rather than looping through the list? In other words, what would be prettier than the following: if foo == 'a' or foo == 'b' or foo == 'c' or foo == 'd': I've just taken up Python, and the languag...

Using Both jQuery And FormEncode To Validate Forms Without Repetition

I'm working on a Pylons-based web app. Because I am sane, I am using jQuery (and plugins) instead of writing raw JavaScript. I am also using FormEncode to validate forms for my app (especially new user registration). FormEncode is great for validating forms after they're submitted. jQuery, when JavaScript is available, validates form...

free implementation of counting user sessions from a web server log?

Web server log analyzers (e.g. Urchin) often display a number of "sessions". A session is defined as a series of page visits / clicks made by an individual within a limited, continuous time segment. The attempt is made to identify these segments using IP addresses, and often supplementary info like user agent and OS, along with a session...

Adding Graph to Reportlab PDF

I have seen many reportlab graphing examples. Generating the graph is not the problem, I can't seem to figure out how to display the graph on the pdf. Here is the code: buffer = StringIO() p = canvas.Canvas(buffer, pagesize = letter) ##### Beginning of code in question d = Drawing(200, 100) pc = Pie() pc.x = 65 pc.y = 15 pc.width = ...

Limit loop to N iterations per minute

Hi, Could someone please give me some help with limiting a loop to N iterations per minute in Python. Lets say I have limit = 5 for items in recvData: # > limit iterations in past minute? -> sleep for 60 seconds from last iterations before proceeding? # ... do work ... How would I do the time check / sleeping to give the c...

Read/Write CSV as binary with Python

I just found out that I can save space\ speed up reads of CSV files. Using the answer of my previous question http://stackoverflow.com/questions/3710263/how-do-i-create-a-csv-file-from-database-in-python And 'wb' for opens w = csv.writer(open(Fn,'wb'),dialect='excel') How can I open all files in a directory and saves all files ...

Is there a high-level profiling module for Python?

I want to profile my Python code. I am well-aware of cProfile, and I use it, but it's too low-level. (For example, there isn't even a straightforward way to catch the return value from the function you're profiling.) One of the things I would like to do: I want to take a function in my program and set it to be profiled on the fly while ...

Google Apps Engine / Django, calling action upon user login?

I'm new to Google Apps Engine (working on an existing project for someone else) and it seems a bit different than Django as far as the login as the login is handled by Google, I'm trying to make it so the app creates a custom cookie for a user upon their logging in but can't seem to find the handler for the login action... I apologize fo...

Django / Python, calling a specific class / function on every user Request

I was looking over the Django documentation on a way to do this but didn't see anything, though I may have missed it as I'm not sure exactly where to look... I want to be able to perform a specific action on every user request, such as instantiating a class and calling one of its functions, however the only way I know of to do this now i...

Python vs Lua for embedded scripting/text processing engine

For a project I'm currently working on, I'm looking to embed a scripting engine into my C++ code to allow for some extensibility down the line. The application will require a fair amount of text processing and the use of regular expressions within these scripts. I know Lua is generally the industry darling when it comes to embedded scr...