python

mobile python 2.6 distribution/development environment?

I'm in an interesting situation. My current computer is going to go in for repairs, and in the meantime I want to get some work done on a friend's computer, but I can't and really don't want to have to set up my development environment on the new PC. Is there a way I can carry around a working Python development environment on a Flash dr...

Strong vs weak typing

The way I understand it, the following is allowed in PHP because it's a weakly-typed language. $var = 'Hello'; $var = 5; I just installed a Windows version of Python 2.6 and I was expecting it NOT to let me change type just like that, but the Python equivalent of the above code works just like in PHP yikes! >>> var = "Hello" >>> type...

Replacing text in Python

I've been looking at the re documentation and at other questions but I keep running into trouble with regex. I need to take what ever is in the [tag] off of the string. string = "Article Name [Tag Name]" #and I want to go to string = "Article Name" I'd really appreciate it if anyone could help. ...

Inherit docstrings in Python class inheritance

I'm trying to do some class inheritance in Python. I'd like each class and inherited class to have good docstrings. So I think for the inherited class, I'd like it to: inherit the base class docstring also append relevant extra documentation to the docstring Is there some "best practice" for doing this sort of docstring manipulation ...

MasterPage like concept in python

We are developing a web based application in python on google app engine platform. I have different pages in web site. What I want is to have a master page like functionality like we have in asp.net where I have just on template and all other pages will use that. How can I do this? I am a beginner in python ...

conditional skip in python if

hi all, i am trying for something like this def scanthefile(): x = 11 if x > 5 """ i want to come out of if and go to end of scanfile """ print x return info update: if have to check for the content size of a file. and if the content size is larger than a value say 500 , then i should go to the end of t...

How to become a great open source programmer of python?

Hi, I'm a C# programmer of web applications. Weeks ago, I asked a question on stackoverflow about What should a software engineer (web) start by learning - Erlang, Haskell, Python, C++, F#. Thanks to all of those who suggested their thoughts and help to make a decision. I've found Python should be the one I should start looking forward...

Popen always run, ignoring the if

I want that when I respond other thing diferent that yes, the subprocess don't run. r = raw_input('\nDo you want play the video?\n\nY:Yes N:No\n\n') if r == "Y" or "y" or "yes" or"yep" or"yeah": message("Playing Video") subprocess.Popen(playvid) else: pass ...

See What Line a Function Was Called From in Python Decorator

Given something like this: @my_decorator my_function(some, args) Is it possible for my_decorator to discover the file and line number my_function was called from? Thanks ...

How do you ask gstreamer if a file can be played?

I'm trying to write a simple command line audio player using the Python Gstreamer bindings. Is there a function in the gstreamer API that determines in advance whether or not a particular file (URI) can be decoded and played by the currently installed set of codecs? ...

give me a code example on 'str.decode' and 'unicode.encode',

print str.decode print unicode.encode thanks ...

Relationship between string module and str

What is the difference or relationship between str and string? import string print str print string ...

Strategies or support for making parts of a Twisted application reloadable?

I've written a specialized JSON-RPC server and just started working my way up into the application logic and finding it is a tad annoying to constantly having to stop/restart the server to make certain changes. Previously I had a handler that ran in intervals to compare module modified time stamps with the past check then reload the mod...

How to create Python egg file

I have questions about egg files in Python. I have much Python code organized by package and I'm trying to create egg files. I'm following instructions, but they are very common. According to that, it seems I need to have a setup.py file. Would you please tell me what I need to put into setup.py file and where it should reside? I sup...

Python Cherrypy 404 Error Handling

I have a web server that has all of the configurations set in the code, but I want to be able to handle all page 404 errors. How would I go about doing this in Python? ...

Is it possible to tell a python script to stop at some point and give you the hand interactively, for example with ipython?

Suppose I have a script that does a lot of stuff, and doesn't work well somewhere near the end. I'd love to be able to add a start_ipython() function at that point, which would stop the script at this point, and let me inspect variables and so on with ipython. How can I do this? ...

Work with Postgres/PostGIS View in SQLAlchemy

Hello there, Two questions: i want to generate a View in my PostGIS-DB. How do i add this View to my geometry_columns Table? What i have to do, to use a View with SQLAlchemy? Is there a difference between a Table and View to SQLAlchemy or could i use the same way to use a View as i do to use a Table? sorry for my poor english. If t...

Python multiple inheritance: Whats wrong doing it dynamically?

Based on this answer, of how __new__ and __init__ are supposed to work in Python, I wrote this code to dynamically define and create a new class and object. class A(object): def __new__(cls): class C(cls, B): pass self = C() return self def foo(self): print 'foo' class B(object): def bar(...

Python: Get importing module's details from within imported module

I'm writing a piece of reusable code to import where I need it, but it needs some info about what is importing it. I have a workaround that does what I want, but it's a bit ugly. Is there a better way? Here is a simplified version of what I'm doing. What I want: Import a method and use it, but look at f in mod2. It needs some info from...

Packaging Python applications with configuration files

I'm using ConfigParser for configuring my application, and now I want to make it easily distributable, and at the same time preserve the configurability. I'm thinking I need a directory with configuration file templates, and some way of generating the configuration to actually use from these. Then I need a place to store it that will w...