problems playing with dates from any month.


hello,
I have a very strange problem and I can't find any solution for that.
I am working on an accounting package which I wish to develop in python.
the simple problem is that I want to knoe how I can know if the given
date is the nth day of a month.
for example if a customer is supposed to pay his installment on every
5th of all months,
I want to know if today is the fifth day (jan the fifth, feb the fifth
etc) for any given month.
I have not found any such function.
if I have looked (or over looked ) in the wrong places I am really sorry.
secondly I also want to know the way in which I can convert a given
string to a date object.
for example if I have a string "29/09/2005", I know it is a valid date
although it is in a string form.
now I want to convert the above string into a real date object.
how can I cast it this way
regards,
Krishnakant.
Posted On: Monday 5th of November 2012 02:16:53 AM Total Views:  206
View Complete with Replies

RELATED TOPICS OF Python Programming PROGRAMMING LANGUAGE




Python's doc problems: sort

Of my Python and Perl tutorial at http://xahlee.org/perl-python/index.html the most popular page is \tSorting in Python and Perl\t� http://xahlee.org/perl-python/sort_list.html For example, in last week, that page is fetched 550 times. The second most popular page, trails quite a distance. Here's the top 3 pages and their number of times fetched: 550 http://xahlee.org/perl-python/sort_list.html 341 http://xahlee.org/perl-python/system_calls.html 222 http://xahlee.org/perl-python/index.html Note that the first 2 pages are far more popular than the entry page the table of contents. Apparently, and also verified by my web log, that people have difficulty in using sort, and they find my pages thru web search engines. ------------------ In 2005, i wrote over ten essays detailing Python's documentation problems. One of them is titled: \tPython Doc Problem Example: sort()\t� http://xahlee.org/perl-python/python_doc_sort.html It's been 3 years, and python has gone from 2.4.x to 2.5.2. Looking at the current version of the doc, apparently, Python doc of that page hasn't improved a bit. I want to emphasize a point here, as i have done quite emphatically in the past. The Python documentation, is the world's worst technical writing. As far as technical writing goes, it is even worse than Perl's in my opinion. Although i disliked Perl very much, in part that it is lead by a cult figure that manipulates and deceives the populace, but there is at least one aspect of Perl community that is very positive, namely, embrace all walks of life. This aspect is taken by a Perl derivative the Pretty Home Page, and its success surpassed Perl, yet without Perl's cult string. Now, in my experience, the Python community, is filled with politics more so than Perl, and far more fucking assholes with high hats. Python priests: go fuck yourselfs. (disclaimer: all statements about actual persons in this post are statements of opinion.) ---------------------- Now, i find it pertinent to post my essay about the sort documentation problem again. The HTML version with colors and formatting is here: http://xahlee.org/perl-python/python_doc_sort.html Below is a abridged textual version. ------------------------------------- Python Doc Problem Example: sort() Python doc \t3.6.4 Mutable Sequence Types\t� at http://python.org/doc/2.4/lib/typesseq-mutable.html in which contains the documentation of the \tsort\t� method of a list. Quote: «...» As a piece of documentation, this is a lousy one. The question Python doc writers need to ask when evaluating this piece of doc are these: * Can a experienced programer who is expert at several languages but new to Python, and also have read the official Python tutorial, can he, read this doc, and know exactly how to use sort with all the options * Can this piece of documentation be rewritten fairly easily, so that the answer to the previous question is a resounding yes To me, the answers to the above questions are No and Yes. Here are some issues with the doc: \t In the paragraph about the \tkey\t� parameter, the illustration given is: \tcmp=str.lower\t�. It should be be \tkey=str.lower\t� \t This doc lacks examples. One or two examples will help a lot, especially to less experienced programers. (which comprises the majority of readers) In particular, it should give a full example of using the comparison function and one with the \tkey\t� parameter. Examples are particularly needed here because these parameters are functions, often with the \tlambda\t� construct. These are unusual and advanced constructs among imperative languages. \t This doc fails to mention what happens when the predicate and the shortcut version conflicts. e.g. \tmyList.sort(cmp=lambda x,y: cmp(x[0], y[0]), key=lambda x: str(x[1]) )\t� \t The notation the Python doc has adopted for indicating the syntax of optional parameters, does not give a clear view just exactly what combination of optional parameters can be omitted. The notation: \ts.sort([cmp[, key[, reverse]]])\t� gives the impression that only trailing arguments can be omitted, which is not true. \t The doc gives no indication of how to omit a optional arg. Should it be \tnul\t�, \tNull\t�, 0, or left empty Since itdoesn't give any examples, doc reader who isn't Python experts is left to guess at how true/false values are presented in Python. \t On the whole, the way this doc is written does not give a clear picture of the roles of the supplied options, nor how to use them. Suggested Quick Remedy: add a example of using the cmp function. And a example using the \tkey\t� function. Add a example of Using oneof them and with reverse. (the examples need not to come with much explanations. One sentence annotation is better than none.) Other than that, the way the doc is laid out with a terse table and run-on footnotes (employed in several places in Python doc) is not inductive. For a better improvement, there needs to be a overhaul of the organization and the attitude of the entire doc. The organization needs to be programing based, as opposed to implementation or computer science based. (in this regard, one can learn from the Perl folks). As to attitude, the writing needs to be Python-as-is, as opposed to computer science framework, as indicated in the early parts of this critique series. Addendum, 200510: Since Python 2.4 released in 2005-03, a new built-in function sorted() was added. There's no mention of it at the doc page of the sort() method. Addendum, 2005-10 Here's further example of Python's extreme low quality of documentation. In particular, what follows focuses on the bad writing skill aspect, and comments on some language design and quality issues of Python. From the Official Python documentation of the sort() method, at: http://python.org/doc/2.4.2/lib/typesseq-mutable.html, Quote: «The sort() method takes optional arguments for controlling the comparisons.» It should be \toptional parameter\t� not \toptional argument\t�. Their difference is that \tparameter\t� indicates the variable, while \targument\t� indicates the actual value. «... for controlling the comparisons.» This is a bad writing caused by lack of understanding. No, it doesn't \tcontrol the comparison\t�. The proper way to say it is that \tthe comparison function specifies an order\t�. «The sort() and reverse() methods modify the list in place for economy of space when sorting or reversing a large list. To remind you that they operate by side effect, they don't return the sorted or reversed list. » This is a example of tech-geeking drivel. The sort() and reverse() methods are just the way they are. Their design and behavior are really not for some economy or remind programers of something. The Python doc is bulked with these irrelevant drivels. These littered inanities dragged down the whole quality and effectiveness of the doc. «Changed in version 2.4: Support for key and reverse was added.» «In general, the key and reverse conversion processes are much faster than specifying an equivalent cmp function. This is because cmp is called multiple times for each list element while key and reverse touch each element only once.» When sorting something, one needs to specify a order. The easiest way is to simply list all the elements as a sequence. That way, their order is clearly laid out. However, this is in general not feasible and impractical. Therefore, we devised a mathematically condensed way to specify the order, by defining a function f(x,y) that can take any two elements and tell us which one comes first. This, is the gist of sorting a list in any programing language. The ordering function, being a mathematically condensed way of specifying the order, has some constraints. For example, the function should not tell us x < y and y < x. (For a complete list of these constraints, see http://xahlee.org/perl-python/sort_list.html ) With this ordering function, it is all sort needed to sort a list. Anything more is interface complexity. The optional parameters \tkey\t� and \treverse\t� in Python's sort method is a interface complexity. What happened here is that a compiler optimization problem is evaded by moving it into the language syntax for programers to worry about. If the programer does not use the \tkey\t� syntax when sorting a large matrix (provided that he knew in advance of the list to be sorted or the ordering function), then he is penalized by a severe inefficiency by a order of magnitude of execution time. This situation, of moving compiler problems to the syntax surface is common in imperative languages. «Changed in version 2.3: Support for None as an equivalent to omitting cmp was added.» This is a epitome of catering towards morons. \tmyList.sort()\t� is perfect but Pythoners had to add \tmyList.sort(None)\t� interface complexity just because idiots need it. The motivation here is simple: a explicit \tNone\t� gives coding monkeys a direct sensory input of the fact that \tthere is no comparison function\t�. This is like the double negative in black English \tI ain't no gonna do it!\t�. Logically, \tNone\t� is not even correct and leads to bad thinking. What really should be stated in the doc, is that \tthe default ordering function to sort() is the \tcmp\t function.\t�. «Starting with Python 2.3, the sort() method is guaranteed to be stable. A sort is stable if it guarantees not to change the relative order of elements that compare equal -- this is helpful for sorting in multiple passes (for example, sort by department, then by salary grade).» One is quite surprised to read this. For about a decade of a language's existence, its sort functionality is not smart enough to preserve order\t A sort that preserves original order isn't something difficult to implement. What we have here is sloppiness and poor quality common in OpenSource projects. Also note the extreme low quality of the writing. It employs the jargon \tstable sort\t� then proceed to explain what it is, then in trying to illustrate the situation, it throws \tmultiple passes\t� and the mysterious \tby department, by salary\t�. Here's a suggested rewrite: \tSince Python 2.3, the result of sort() no longer rearrange elements where the comparison function returns 0.\t� Xah xah@xahlee.org \t http://xahlee.org/ \t
VIEWS ON THIS POST

83

Posted on:

Sunday 4th November 2012
View Replies!

Re: Singleton implementation problems

Urizev wrote: > Hi > > I have developed the singleton implementation. However I have found a > strange behaviour when using from different files. The code is > attached. > > Executing main > New singleton: > > New singleton: > > I do not know why, but it creates two instances of the singleton. Does > anybody know why Do you see it now I snipped the irrelevant output The problem is the structure of your program. The myset module is imported twice by Python, once as "myset" and once as "__main__". Therefore you get two distinct MySet classes, and consequently two distinct MySet.__instance class attributes. Move the if __name__ == "__main__": ... statements into a separate module, e. g. main.py: import myset import member if __name__ == "__main__": print "Executing main" set1 = myset.MySet() set2 = myset.MySet() mbr1 = member.Member() mbr2 = member.Member() mbr3 = member.Member() Now main.py and member.py share the same instance of the myset module and should work as expected. Peter
VIEWS ON THIS POST

82

Posted on:

Sunday 4th November 2012
View Replies!

Re: rlcompleter and wxPython, problems ...

En Tue, 30 Sep 2008 16:06:07 -0300, Stef Mientki escribi: > Gabriel Genellina wrote: >> En Sun, 28 Sep 2008 19:25:30 -0300, Stef Mientki >> escribi: >> >>> I'm trying to implement autocompletion into my editor. >>> But I find some weird behavior, >>> or at least I don't have the faintest idea why this behavior occures, >>> and even more important how to solve it >>> In the example below I try to autocomplete " wx.s" , which in my >>> humble opinion should at least produce "wx.stc" (and some others ). >> >> wx is a package. Modules within the package are not, by default, >> attributes of the package - unless they're imported in __init__.py or >> your code imports them. >> So the autocompleter is doing the right thing > in what perspective > the autocompleter is only meant to assist the program writer ;-) It's hard to write an autocompleter that does the right thing in all cases For a package, you have several sources for possibly valid attributes: - its dir() (that is, the package object's own attributes) - the __all__ attribute, when it exists - the list of modules inside the package directory or directories (given by its __path__ attribute) Sometimes __init__.py is empty - and enumerating the modules inside the directory is the right thing to do. Sometimes the author explicitely imports things in __init__.py, things that comprise the public interfase to the package. In that case I'd not like to see "private" modules appearing in the list. Combine with __all__, which might be defined or not. Mix all those, choose your own autocomplete algorithm, and see what happens... >> - wx.stc does not exist until it is explicitely imported. > I guess I've to study the package. > For the moment I'll implement a user editable list of additions. > > But with your remarks I tried __all__ > And now I wonder why rlcompleter is not simply using "wx.__all__", > it than does gets all the items __all__ isn't always defined. It's only used when you do "from xxx import *" AFAIK. -- Gabriel Genellina
VIEWS ON THIS POST

93

Posted on:

Sunday 4th November 2012
View Replies!

Re: rlcompleter and wxPython, problems ...

Gabriel Genellina wrote: > En Sun, 28 Sep 2008 19:25:30 -0300, Stef Mientki > escribi: > >> I'm trying to implement autocompletion into my editor. >> But I find some weird behavior, >> or at least I don't have the faintest idea why this behavior occures, >> and even more important how to solve it >> In the example below I try to autocomplete " wx.s" , which in my >> humble opinion should at least produce "wx.stc" (and some others ). > > wx is a package. Modules within the package are not, by default, > attributes of the package - unless they're imported in __init__.py or > your code imports them. > So the autocompleter is doing the right thing in what perspective the autocompleter is only meant to assist the program writer ;-) > - wx.stc does not exist until it is explicitely imported. I guess I've to study the package. For the moment I'll implement a user editable list of additions. But with your remarks I tried __all__ And now I wonder why rlcompleter is not simply using "wx.__all__", it than does gets all the items cheers, Stef
VIEWS ON THIS POST

88

Posted on:

Sunday 4th November 2012
View Replies!

BeautifulSoup: problems with parsing a website

Hy , I'm using the python-framework BeautifulSoup(BS) to parse some information out of a german soccer-website. I spend some qualitiy time with the BS-docs, but I couldn't really figure out how to get what I was looking for. Here's the deal: I want to parse the article shown on the website. To do so I want to use the Tag " " as a starting-point. When I have found the Tag I somehow want to get all following "br"-Tags until there is a new CSS-Class Style is coming up. I tried several options in the find()-command, but nothing seems to work.(like: soup.find('br',attrs={'class':'txt_fliesstext'}, text =True) - This one comes with a thound addtional Tag that I don't want to have, or soup.find(attrs={'class':'txt_fliesstext'}) - This gives me a much better Result, but in this case I only get some few Tags, instead of all the Tags I want) Any suggestions
VIEWS ON THIS POST

147

Posted on:

Sunday 4th November 2012
View Replies!

SVN access with pysvn under Cygwin (Installation problems)

I'm building Python tools to wrap up access to our Subversion / SVN source control system. It's to run on my desktop (Cygwin under Windows XP) and then later under Redhat. Trying to install the pysvn module I'm running into problems getting it to work under Cygwin. Works fine from a Windows command prompt, with both the svn_cmd.py example and my own Python code. Under Cygwin though I just get import failures. pysvn/__init__.py seems to be invoked happily enough, but then fails when it tries to import _pysvn_2_5.pyd $ python svn_cmd.py Traceback (most recent call last): File "svn_cmd.py", line 10, in import pysvn File "/usr/lib/python2.5/pysvn/__init__.py", line 104, in import _pysvn_2_5 ImportError: No module named _pysvn_2_5 Is there some trick to getting .pyd to work under Cygwin I've tried the obvious twiddling with environment variables (and regedit), but I'm just guessing blindly.
VIEWS ON THIS POST

113

Posted on:

Sunday 4th November 2012
View Replies!

Re: Singleton implementation problems

On Jul 3, 6:58 pm, Urizev wrote: > Hi > > I have developed the singleton implementation. However I have found a > strange behaviour when using from different files. The code is > attached. > > Executing main > new MySet object > No singleton instance > New singleton: > > new MySet object > There is a singlenton instance > new Member > new MySet object > No singleton instance > New singleton: > > new Member > new MySet object > There is a singlenton instance > new Member > new MySet object > There is a singlenton instance > > I do not know why, but it creates two instances of the singleton. Does > anybody know why Because __init__() is called to initialize the state of an object *after* it has already been created. You should create a "new-style" class and define __new__() instead. Here's a working version: class Singleton(object): # new-style class def __new__(cls, *args, **kwds): # return the singleton (if already created) try: return cls.__dict__['__singleton'] except KeyError: # raised only the first time for a given class # create the singleton and store it to the class namespace singleton = object.__new__(cls, *args, **kwds) setattr(cls, '__singleton', singleton) return singleton class X(Singleton): def __init__(self, a): self.a = a assert X(1) is X(2) Note however that the classic Singleton pattern is usually frowned upon in Python; the preferred approach is to use (module level) globals. Also search for the "Borg pattern". George
VIEWS ON THIS POST

146

Posted on:

Sunday 4th November 2012
View Replies!

Re: problems with opening files due to file's path

Alexnb wrote: > Okay, so what I want my program to do it open a file, a music file in > specific, and for this we will say it is an .mp3. Well, I am using the > system() command from the os class. [...] > > system("\"C:\Documents and Settings\Alex\My Documents\My > Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma\"") > [...] Try os.startfile() instead. It should work better. -- Gerhard
VIEWS ON THIS POST

108

Posted on:

Sunday 4th November 2012
View Replies!

Server side cookie problems

I am trying to set a cookie on a client computer using the Cookie module however all I get is the text being printed in the browser window. Can anyone point me in the right direction so that the cookie data is set without it appearing in the browser A shortened version of the code is below, in the full version there is also userID check, this seems to work ok. I have removed that portion for the time being as its the writing part that is the problem. import sys, os, string, cgi, Cookie, urllib2 from types import ListType cookie = Cookie.SimpleCookie() cookieHdr = os.environ.get("HTTP_COOKIE", "") cookie.load(cookieHdr) def writetocookie(number): #writes the ID of the database entry to a cookie cookie["dataid"]=number print "Content-Type: text/html" print print "Set-Cookie: dataid=",cookie["dataid"].value writetocookie(1) I presume this is not the correct way to write a cookie, the examples I have found online don't seem to provide much more information. Kind regards, rod
VIEWS ON THIS POST

117

Posted on:

Sunday 4th November 2012
View Replies!

os.rename() problems on OS X

hello, i recently had the job of having to rename about 200 files. The source for the renaming was a bunch of names in a file. I know next to nothing when it comes to bash scripting (which would have seemed the obvious choice) so i used python. The files i was renaming were canon raw files (.CR2). my problem is that after i rename the files, OS X will no longer render the thumbnails for the files, and preview is no longer the default app for viewing them. Does anyone have an idea as to why this is
VIEWS ON THIS POST

148

Posted on:

Sunday 4th November 2012
View Replies!

Memory usage problems with imports and python

I am a developer relatively new to python and brand new to pygtk development. I wanted to write a bloglines tray icon notifier for my linux box. Everything is working quite well functionality wise, but the memory footprint is horrible. This little tray icon that simply has a thread for updates, a gtk.StatusIcon, a few relatively small dict objects and a context menu is running at around 20-25 MB of memory. Doing some initial research, starting python up takes 1 MB, importing GTK bumps it up to 4 MB, importing other libraries jumps up to 7 MB and so on. IMO this code should take up a maximum of 2-4 MB (based on other linux tray icons and docking programs). Is this a problem with (a) python, (b) poor memory management of the python libraries I am using, especially py/gtk or (c) something I am doing wrong as a developer For anyone who wants to help, the code is open source and can be viewed here: http://pybloglines.svn.sourceforge.n...c/pybloglines/ The "PyBloglinesNotifier" file is the main python program and imports code from within the bloglines folder. Thank you, Andrew
VIEWS ON THIS POST

228

Posted on:

Monday 5th November 2012
View Replies!

Re: [win32] spawn background process and detach it w/o problems

En Thu, 08 Nov 2007 11:09:02 -0300, Dmitry Teslenko escribi: > How to write portable (win32, unix) script that launches another > program and continues its execution Use the subprocess module. -- Gabriel Genellina
VIEWS ON THIS POST

148

Posted on:

Monday 5th November 2012
View Replies!

Parsing problems: A journey from a text file to a directory tree

Hi everybody, Some of my colleagues want me to write a script for easy folder and subfolder creation on the Mac. The script is supposed to scan a text file containing directory trees in the following format: [New client] |-Invoices |-Offers |--Denied |--Accepted |-Delivery notes As you can see, the folder hierarchy is expressed by the amounts of minuses, each section header framed by brackets (like in Windows config files). After the scan process, the script is supposed to show a dialog, where the user can choose from the different sections (e.g. 'Alphabet', 'Months', 'New client' etc.). Then the script will create the corresponding folder hierarchy in the currently selected folder (done via AppleScript). But currently I simply don't know how to parse these folder lists and how to save them in an array accordingly. First I thought of an array like this: dirtreedb = {'New client': {'Invoices': {}, 'Offers': {'Denied': {}, 'Accpeted': {}}, 'Delivery notes': {}}} But this doesn't do the trick, as I also have to save the hierarchy level of the current folder as well... Argh, I really don't get my head around this problem and I need your help. I have the feeling, that the answer is not that complicated, but I just don't get it right now... Your desperate, Martin , On Sep 19, 4:51 am, "Michael J. Fromberger" wrote: > . > . # This expression matches "header" lines, defining a new section. > . new_re = re.compile(r'\[([\w ]+)\]\s*$') Directory names can contain more different characters than those which match [\w ] ... and which ones depends on the OS; might as well just allow anything, and leave it to the OS to complain. Also consider using line.rstrip() (usually a handy precaution on ANY input text file) instead of having \s*$ at the end of your regex. > . > . while new_level < len(state): > . state.pop() Hmmm ... consider rewriting that as the slightly less obfuscatory while len(state) > new_level: state.pop() If you really want to make the reader slow down and think, try this: del state[new_level:] A warning message if there are too many "-" characters might be a good idea: [foo] |-bar |-zot |---plugh > . > . state[-1][key] = {} > . state.append(state[-1][key]) > . And if the input line matches neither regex > . return out > > To call this, pass a file-like object to parse_folders(), e.g.: > > test1 = ''' > [New client]. Won't work with the dot on the end. > Michael J. Fromberger | Lecturer, Dept. of Computer Science
VIEWS ON THIS POST

142

Posted on:

Monday 5th November 2012
View Replies!

problems using pythom tempfile module

, I'm trying to test the tempfile module with the following script, which basically creates a temporary file, fills the file with some test data and prints it. import tempfile t = tempfile.TemporaryFile() t.write("lalalala") t.flush() print t.read() Unfortunately, the print statement gives me an empty string. Can somebody tell me what I'm doing wrong regards Samir
VIEWS ON THIS POST

123

Posted on:

Monday 5th November 2012
View Replies!

encoding problems

I would like to transform reST contents to HTML, but got problems with accented chars. Here's a rather simplified version using SVN Docutils 0.5: %------------------------------------------------------------- #!/usr/bin/env python # -*- coding: utf-8 -*- from docutils.core import publish_parts class Post(object): def __init__(self, title='', content=''): self.title = title self.content = content def _get_html_content(self): return publish_parts(self.content, writer_name="html")["html_body"] html_content = property(_get_html_content) # Instanciate 2 Post objects p1 = Post() p1.title = "First post without accented chars" p1.content = """This is the first. ....blabla .... end of post...""" p2 = Post() p2.title = "Second post with accented chars" p2.content = """Ce poste possde des accents : """ for post in [p1,p2]: print post.title, "\n" +"-"*30 print post.html_content %------------------------------------------------------------- The output gives me : First post without accented chars ------------------------------ This is the first. ....blabla .... end of post... Second post with accented chars ------------------------------ Traceback (most recent call last): File "C:\Documents and Settings\kib\Bureau\Projets\python\dbTest\rest_error.py", line 30, in print post.html_content UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 39: ordinal not in range(128) Any idea of what I've missed
VIEWS ON THIS POST

141

Posted on:

Monday 5th November 2012
View Replies!

python 2.5 problems

Finally deleted 2.2 and loaded 2.5 (see below), using the msi, on my XP partition. Having intermittent system crashes. Assumed a corrupt download, so deleted and did another download/install. Same problems. The associated DLLs when XP says that it must shut down the idle shell are not consistent. So is there something not stable about ver 2.5 on XP Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32
VIEWS ON THIS POST

203

Posted on:

Monday 5th November 2012
View Replies!

[win32] spawn background process and detach it w/o problems

! How to write portable (win32, unix) script that launches another program and continues its execution I've looked at spawn*() but it doesn't look in PATH dirs on windows so it's totally unusable when you don't know where exactly program is. I've looked at fork() way but there's no fork for windows. My current solution is thread.start_new(os.system, (
VIEWS ON THIS POST

216

Posted on:

Monday 5th November 2012
View Replies!

some problems with mod_python

Johan a crit : > Hi > > I have installed and tested this on centos, fedora and freebsd all > give the same problem so I guess I missed some steps. > > I have compiled bot apache (2.2.4) and mod_python (3.3.1) according to > the docs and no problem with this. > But when I have made everything about testing mod_python an browse to > http://server/test and there expecting to see " world" I instead > get an index of contents in this directory. If I go to http://server/test/mptest.py > it works. No errors in any log either. > > What Have I missed The difference between AddHandler and SetHandler in apache's conf. > This I added to httpd.conf > > owOverride > AddHandler mod_python .py > PythonHandler mptest > PythonDebug On > Your problem is with Apache configuration, not with mod_python. The AddHandler directive maps /*.py to your handler. So you have to call .py to trigger the deed behaviour. If you want *any* url under to be handled by mptest, you need to use SetHandler, not AddHandler.
VIEWS ON THIS POST

223

Posted on:

Monday 5th November 2012
View Replies!

insert string problems..

Hi.. I want to insert some data to postgresql.. My insert code: yer="019" cursor.execute("INSERT INTO ids_%s (id) VALUES (%s)", (yer, id)) I don't want to use % when the insert operation. in this code give me this error: psycopg2.ProgrammingError: syntax error at or near "'019'" LINE 1: SELECT link_id from linkkeywords_'019' if i do int(yer) , 019 change to 19 .. How can i do int yer string with 0
VIEWS ON THIS POST

180

Posted on:

Monday 5th November 2012
View Replies!

Using arrays in Python - problems.

, ! I've just started to use Python and its a lovely language! I've previously programmed in Fortran 95 and have just began to use numpy. I'm having a few problems with arrays in Python though and wondered if someone could offer me some advice I wrote the following Fortran code to randomly generate numbers from a log-normal distribution for use in a Monte Carlo model: do n=1,shotcount F(n)=G05DEF(F_mean,F_sd) enddo The array F(n) is dynamically allocated earlier on and is sized with reference to shotcount, the number of iterations the model performs. The problem is I can't get something like this to run in Python using numpy, and for the size of the array to be sized dynamically with reference to the variable shotcount. I acknowledge that my knowledge of Python is still really basic (I only started learning it a few days ago) and I'm trying to get out of the Fortran programming mindset but I'm stuck and don't seem to be able to get any further. If anyone could help I'd be really grateful.
VIEWS ON THIS POST

238

Posted on:

Monday 5th November 2012
View Replies!