As a complete beginner with no programming experience, I am trying to find beautiful Python code to study and play with. Please answer by pointing to a website, a book or some software project.
I have the following criterias:
complete code listings (working, hackable code)
beautiful code (highly readable, simple but effective)
instruc...
In Python, I want to make selected instance attributes of a class be readonly to code outside of the class. I want there to be no way outside code can alter the attribute, except indirectly by invoking methods on the instance. I want the syntax to be concise. What is the best way? (I give my current best answer below...)
...
Say I have the following string:
"I am the most foo h4ck3r ever!!"
I'm trying to write a makeSpecial(foo) function where the foo substring would be wrapped in a new span element, resulting in:
"I am the most <span class="special">foo></span> h4ck3r ever!!"
BeautifulSoup seemed like the way to go, but I haven't been able to make it ...
for working with MS word files in python, there is python win32 extensions, which can be used in windows. How do I do the same in linux?
Is there any library?
...
I'm using Python, and would like to insert a string into a text file without deleting or copying the file. How can I do that?
...
Is there any python module for rendering a HTML page with javascript and get back a DOM object?
I want to parse a page which generates almost all of its content using javascript.
...
I have a TurboGears application I'd like to run through Facebook, and am looking for an example TurboGears project using pyFacebook or minifb.py. pyFacebook is Django-centric, and I can probably figure it out, but this is, after all, the lazy web.
...
Intro: I'm trying to migrate our Trac SQLite to a PostgreSQL backend, to do that I need psycopg2. After clicking past the embarrassing rant on www.initd.org I downloaded the latest version and tried running setup.py install. This didn't work, telling me I needed mingw. So I downloaded and installed mingw.
Problem: I now get the followin...
I could swear I've seen the function (or method) that takes a list, like this [3,7,19] and makes it into iterable list of tuples, like so: [ (0,3),(1,7),(2,19) ] to use it instead of
for i in range(len(name_of_list)):
name_of_list[i]=something
but I can't remember the name and "iterate list" in Google gets nothing.
...
I have drawn an image in the device context using python, and i want to move it somothly/animate either vertically or horizontally? What algorithm should i use?
Where can i get info for this kind of tasks in python?
...
Is there a good, free Python IDE for Windows? I really need some good debugging abilities.
...
Almost every Python web framework has a simple server that runs a wsgi application and automatically reloads the imported modules every time the source gets changed. I know I can look at the code and see how it's done, but that may take some time and I'm asking just out of curiosity. Does anyone have any idea how this is implemented?
...
Is there a way to determine how many capture groups there are in a given regular expression?
I would like to be able to do the follwing:
def groups(regexp, s):
""" Returns the first result of re.findall, or an empty default
>>> groups(r'(\d)(\d)(\d)', '123')
('1', '2', '3')
>>> groups(r'(\d)(\d)(\d)', 'abc')
('', '...
I'm a pretty inexperienced programmer (can make tk apps, text processing, sort of understand oop), but Python is so awesome that I would like to help the community. What's the best way for a beginner to contribute?
...
I'm trying to generate customized xml files from a template xml file in python.
Conceptually, I want to read in the template xml, remove some elements, change some text attributes, and write the new xml out to a file. I wanted it to work something like this:
conf_base = ConvertXmlToDict('config-template.xml')
conf_base_dict = conf_ba...
Greetings, currently I am refactoring one of my programs, and I found an interesting problem.
I have Transitions in an automata. Transitions always have a start-state and an end-state. Some Transitions have a label, which encodes a certain Action that must be performed upon traversal. No label means no action. Some transitions have a co...
I need to parse strings like that "2008-09-03T20:56:35.450686Z" into the python's datetime?
I have found only strptime in the python 2.5 std lib, but it not so convinient.
Which is the best way to do that?
Update:
It seems, that python-dateutil works very well. I have found that solution:
d1 = '2008-09-03T20:56:35.450686Z'
d2 = date...
Hello Stack-Overflow,
Here is my situation. I have a list of data that looks like this:
[(id__1_, description, id_type), (id__2_, description, id_type), ... , (id__n_, description, id_type))
The data is loaded from multiple files that all belong to the same grouping. In each grouping there could be multiples of the same id, each comin...
Should I try to actually upgrade my existing app, or just rewrite it mostly from scratch, saving what pieces (templates, etc) I can?
...
PEP 08 states:
Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants.
However if the class/method/function that I am importing is only used in rare cases, surely it is more efficient to do the import when it is needed?
Isn't this:
class SomeClass(obje...