python

writeline problem in python

hi, I have a very basic problem. I am learning my first steps with python & scripting in general and so even this makes me wonder: I want to read & write lines to new file: ifile=open("C:\Python24\OtsakkeillaSPSS.csv", "r") ofile = open("C:\Python24\OtsakkeillaSPSSout.csv", "w") #read first line with headers line1 = ifile.readline()...

How would you inherit from and override the django model classes to create a listOfStringsField?

I want to create a new type of field for django models that is basically a ListOfStrings. So in your model code you would have the following: models.py: from django.db import models class ListOfStringsField(???): ??? class myDjangoModelClass(): myName = models.CharField(max_length=64) myFriends = ListOfStringsField() # ...

making project on double data compression..please help...

m making project on double data compression which uses the lossless data compression technique.. can any one tell me how should i procede?? m making project for the first tim.. please help me frnds... ...

django-timezones

I am trying to setup django-timezones but am unfamiliar on how to go about this. The only info that I have found is here: http://www.ohloh.net/p/django-timezones class MyModel(Model): timezone = TimeZoneField() datetime = LocalizedDateTime('timezone') I also tried looking through the pinax code or any other projects that us...

Best way to have full Python install under cygwin/XP?

Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not like MS; I thought if I...

Is it possible to go into ipython from code?

For my debugging needs,pdb is pretty good. However, it would be MUCH cooler ( and helpful ) if I could go into ipython. Is this thing possible? ...

Do I test a class that does nothing?

In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class: class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, environment_name): pass...

Special chars in Python

Hi, i have to use special chars in my python-application. For example: ƃ I have information like this: U+0183 LATIN SMALL LETTER B WITH TOPBAR General Character Properties In Unicode since: 1.1 Unicode category: Letter, Lowercase Various Useful Representations UTF-8: 0xC6 0x83 UTF-16: 0x0183 C octal escaped UTF-8: \306\203 XML deci...

Python object has no referrers but still accessible via a weakref?

Should it be possible for gc.get_referrers(obj) to return an empty list for an object, but the object still be accessible through a weak reference? If so how would I start trying to identify the cause for this object not being garbage collected? Edit: I'm not sure exactly how a code sample would help in this case - there's obviously a ...

wxPython, how do I fire events?

Hi, I am making my own button class, subclass of a panel where I draw with a DC, and I need to fire wx.EVT_BUTTON when my custom button is pressed. How do I do it? ...

How can I obtain the full AST in Python?

I like the options offered by the _ast module, it's really powerful. Is there a way of getting the full AST from it? For example, if I get the AST of the following code : import os os.listdir(".") by using : ast = compile(source_string,"<string>","exec",_ast.PyCF_ONLY_AST) the body of the ast object will have two elements, an i...

To understand Typeset for PythonPath

One recommends me the following code apparently only in .zshrc without explaining its purpose clearly. typeset -U PYTHONPATH I am interested in how you can use the code in .bashrc. My Bash goes upset about the command. How can you use the command in Bash? ...

Need some help with python string / slicing operations

This is a very newbie question and i will probably get downvoted for it, but i quite honestly couldn't find the answer after at least an hour googling. I learned how to slice strings based on "exact locations" where you have to know exactly where the word ends. But i did not find any article that explained how do it on "non static" strin...

How Do I Use A Decimal Number In A Django URL Pattern?

I'd like to use a number with a decimal point in a Django URL pattern but I'm not sure whether it's actually possible (I'm not a regex expert). Here's what I want to use for URLs: /item/value/0.01 /item/value/0.05 Those URLs would show items valued at $0.01 or $0.05. Sure, I could take the easy way out and pass the value in cents so...

How to split two nested lists and combine the parts to create two new nested lists

I'm trying to code a simple genetic programming utility in python. But right now I'm stuck at the crossover/mate function for my trees. The trees are built by nested lists and look something like this: # f = internal node (a function), c = leaf node (a constant) tree1 = [f, [f, [f, c, c], [f, c, c]], [f, [f, c, c], [f, c, c]]] tree2 = [...

Is it possible to encode (<em>asdf</em>) in python Textile?

I'm using python Textile to store markup in the database. I would like to yield the following HTML snippet: (<em>asdf</em>) The obvious doesn't get encoded: (_asdf_) -> <p>(_asdf_)</p> The following works, but yields an ugly space: ( _asdf_) -> <p>( <em>asdf</em>) Am I missing something obvious or is this just not possi...

How to Redirect To Same Page on Failed Login

The Django framework easily handles redirecting when a user fails to log in properly. However, this redirection goes to a separate login page. I can set the template to be the same as the page I logged in on, but none of my other objects exist in the new page. For example, I have a front page that shows a bunch of news articles. On the ...

How can I make setuptools ignore subversion inventory?

When packaging a Python package with a setup.py that uses the setuptools: from setuptools import setup ... the source distribution created by: python setup.py sdist not only includes, as usual, the files specified in MANIFEST.in, but it also, gratuitously, includes all of the files that Subversion lists as being version controlled ...

creating non-reloading dynamic webapps using Django

As far as I know, for a new request coming from a webapp, you need to reload the page to process and respond to that request. For example, if you want to show a comment on a post, you need to reload the page, process the comment, and then show it. What I want, however, is I want to be able to add comments (something like facebook, wh...

how do i filter an itertools chain() result?

in my views, if i import an itertools module: from itertools import chain and i chain some objects with it: franktags = Frank.objects.order_by('date_added').reverse().filter(topic__exact='art') amytags = Amy.objects.order_by('date_added').reverse().filter(topic__exact='art') timtags = Tim.objects.order_by('date_added').reverse().fi...