subclassing pyrex extension types in python
Hi All I am trying to subclass an extension type in Python and add attributes to the new class but I keep getting errors. I read the "Extension Types" document on the Pyrex website but I couldn't get an answer from it. Here's the Spam extension type from Pyrex website: cdef class Spam: cdef int amount def __new__(self): self.amount = 0 def get_amount(self): return self.amount Once compiled, here's how I am using this: import spam class mySpam(spam.Spam): def __init__(self, name1=None, name2=None): spam.Spam.__init__(self) self.name1 = name1 self.name2 = name2 When I run this Python code, I get an error "TypeError: 'name2' is an invalid keyword argument for this function" Is there something I need to know about Pyrex extension types and keyword arguments ? I tried to google for this but couldn't come up with anything. Thanks ! Nitin -- http://mail.python.org/mailman/listinfo/python-list
Req: Python Developer : Direct CLient
Hi, Please send me your resume if you are interested in it. Python Developer Location: Sebastapol, CA Duration: 3 Months Python web application development. Systems integration. RESTful architectures and Web standards. Familiar with the following: JVM and java tools. Creating documentation. Workable knowledge of relational databases and NoSQL solutions Thanks Nitin Singhal | RJT Compuquest Inc. 23440 Hawthorne Blvd., Suite 210, Torrance, CA 90505 nsing...@rjtcompuquest.com www.rjtcompuquest.com Direct: 310 961 5807 Voice: 866-978-0384 Ext- 46 Fax: 310-378-6867 -- http://mail.python.org/mailman/listinfo/python-list
ctypes pointer
Hi, I wish to call a function in c++ dll which returns a unicode array from python. extern "c" { __declspec(dllexport) int test(wchar_t** ppText) { *ppText = new wchar_t[30]; wcscpy(*ppText, L"this is a test"); return 0; } __declspec(dllexport) int FreeString(wchar_t** ppText) { delete [] *ppText; return 0; } } In python I'm doing this import ctypes dll = ctypes.cdll.LoadLibrary(r"x") func = dll.test func.argtypes = [ ctypes.POINTER(ctypes.c_wchar_p)] funcDel = dll.FreeString funcDel.argtypes = [ctypes.POINTER(ctypes.c_wchar_p)] a = ctypes.c_wchar_p('') z = ctypes.pointer(a) n= func(z) print a /* displays "this is a test" */ /* is this correct way to return charater array */ /* will memory allocated in c++ function be freed by python */ /* or should I call */ n = funcDel(z) thanks, Nitin. -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing array from java to python
can you execute the java code from python and get the result stored as python variable os.system() On Thu, Jun 2, 2011 at 4:17 PM, loial wrote: > Unfortunately using jpython or json are not options at the moment > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: How to stop iteration
check length of input string with if stri.len > 3 On Sun, Jun 5, 2011 at 8:35 PM, Ganapathy Subramanium < sganapathy.subraman...@gmail.com> wrote: > Hi All, > > I'm a new bie to programming and need some assistance in this code. > > I have a function which will split the given string into 3 characters each > and I want to achieve this by recursion. > > I have written the following code, but I don't know how to stop the > recursion when the length of the remaining string is less than or equal to 3 > characters. Any inputs on this please? > > string = 'This is a sample python programming' > space = 2 > final_result = [] > def strsplit(stri, spa): > s = stri[:spa] > final_result.append(s) > stri = stri[spa:] > strsplit(stri,spa) > return final_result > c = strsplit(string,space) > print 'The final result is: ', c > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: How good is security via hashing
Have you tried using UUID module? Its pretty handy and comes with base64 encoding function which gives extremely high quality randon strings ref: http://stackoverflow.com/questions/621649/python-and-random-keys-of-21-char-max On Tue, Jun 7, 2011 at 3:48 PM, Robin Becker wrote: > A python web process is producing files that are given randomized names of > the form > > hh-MMDDhhmmss-.pdf > > where rrr.. is a 128bit random number (encoded as base62). The intent of > the random part is to prevent recipients of one file from being able to > guess the names of others. > > The process was originally a cgi script which meant each random number was > produced thusly > > > pid is process id, dur is 4 bytes from /dev/urandom. > > random.seed(long(time.time()*someprimeint)|(pid<<64)|(dur<<32)) > rrr = random.getrandbits(128) > > > is this algorithm safe? Is it safe if the process is switched to fastcgi > and the initialization is only carried out once and then say 50 rrr values > are generated. > -- > Robin Becker > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: The pythonic way equal to "whoami"
import getpass user = getpass.getuser() On Tue, Jun 7, 2011 at 7:54 PM, TheSaint wrote: > Hello, > I was trying to find out whose the program launcher, but os.environ['USER'] > returns the user whom owns the desktop environment, regardless the program > is called by root. > I'd like to know it, so the program will run with the right privileges. > > Is there any standard function on python, that will do it? > -- > goto /dev/null > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Running a Python script on a web server
There are few options available with mod_python + apache configuration but it comes with limitation as the scripts will be running on servers and you will need to parse the requests and inputs as a web request to the script On Wed, Jun 8, 2011 at 9:34 AM, Chris Angelico wrote: > On Wed, Jun 8, 2011 at 1:10 PM, Abhijeet Mahagaonkar > wrote: > > So i have requested a server space so I need some inputs on how i will be > > able to "host" these scripts on a webserver and have them run on browsers > > rather than on individual systems. > > Python doesn't normally run in a web browser. There's two easy options: > > 1) Use very simple web hosting that lets people download scripts and > run them. Anything can do this, but all you gain is that they don't > have to keep a collection of scripts / EXEs on their hard drives. > > 2) Run the Python scripts on the web server. I don't know whether this > is even possible in your situation; it would turn them into quite > different tools. > > I have no experience with it, but Jython can make applets. Again, > though, these would be quite different tools from simple Python > scripts. Web browsers aren't generally happy for in-browser scripts > to, for instance, read and write files on the user's hard drive. > > I think you're ultimately going to need to keep on distributing those > scripts. But if you get your users to install a Python interpreter, > they need only install it once and then you can distribute all your > scripts in .py format rather than py2exeing them all. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Application monitoring
We use nagios for such monitoring On Tue, Aug 16, 2011 at 4:47 PM, Abhishek Bajpai wrote: > I need to monitor applications like apache, mysql etc there live > status, errors etc on my LAN is there any tool or lib for this any > help will be appreciated thanks in advance > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting an array of string to array of float
did you try type casting with float ? On Fri, Mar 25, 2011 at 8:49 PM, joy99 wrote: > Dear Group, > > I got a question which might be possible but I am not getting how to > do it. > > If I have a list, named, > list1=[1.0,2.3,4.4,5.5] > > Now each element in the array holds the string property if I want to > convert them to float, how would I do it? > > Extracting the values with for and appending to a blank list it would > not solve the problem. If appended to a blank list, it would not > change the property. > > If any one of the learned members can kindly suggest any solution? > > Thanks in advance. > Best Regards, > Subhabrata. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: How to Use Setuptools, Alternatives?
there is a very good article on python packaging http://www.aosabook.org/en/packaging.html On Tue, May 31, 2011 at 12:18 AM, dough wrote: > On May 29, 10:41 pm, ray wrote: > > I have Python 2.7 on Win7 Pro on a tightly locked down desktop. I > > would like to install Networkx from an egg. From what I have read, > > Setuptools can be used for this. > > > > I don't know how to install Setuptools. The exe will not work. On > > execution, it reports that the Python version is not included in the > > registry. Further, I can not input the version and location on the > > subsequent installation screen, the fields will not accept focus so I > > can not input the values. > > > > Since the exe will not install, I considered using the Setuptools > > egg. But it requires Setuptools. It appears to be a circle. > > > > You're right. Since Setuptools is distributed as an egg, and Python > doesn't natively support eggs, > there can be a "chicken-and-egg" situation. > > > What are some suggestions for installing this? > > > > Thanks, > > ray > > You can try downloading ezsetup.py and running it as a python script > (i.e. python ezsetup.py). > It will locate and download the latest version of Setuptools for your > platform and install it. > If HTTP access is blocked, just place the desired egg in the same > folder as ezsetup.py and run > the script again. > > Assuming you can get Setuptools installed correctly, it puts a program > called easy_install.exe > in your \Scripts folder. You can then just run (from the > command line): > > easy_install > > It will hunt, download and install the latest version of the package > for your platform. > You may want to add the path to the Scripts folder to your PATH > environment variable so > you can just run easy_install from any current working directory. > > Hope that helps, > > Doug > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Trouble using telentlib
I sarched the existing threads but didnt find an answer to this. I am writing simple script which uses telentlib to open a session with a unix machine and run "tail -f logfile.txt" on one of the logfiles. import telnetlib HOST = "192.X.X.X" user = "myname" password = "mypass" tn = telnetlib.Telnet(HOST) tn.read_until("login: ") tn.write(user + "\n") if password: tn.read_until("Password: ") tn.write(password + "\n") tn.write("tail -f /tmp/logfile.txt\n") # what do i write here ? # tn.write("exit\n") I want to read every line of the output into a string and run regex on it. I tried tn.interact() which does show me the ouput but the CPU usage on my win2k machine reaches 99% !! :( How do i execute a command and then read its output, then another command and read its output and so on. I tried to find docs on telnetlib but in vain. Can somebody guide me please Thanks Nitin -- http://mail.python.org/mailman/listinfo/python-list
Multiple Inheritance __slots__ problem
Hello, Can anyone tell why am I getting this error and how to work around this problem. >>> class Klass(object): ... __slots__ = ( 'x' ) ... >>> class Klass1(object): ... __slots__ = ( 'y' ) ... >>> class Klass(Klass, Klass1): ... __slots__ = ( 'z' ) ... Traceback (most recent call last): File "", line 1, in ? TypeError: multiple bases have instance lay-out conflict I need to define slots in these classes and also need to inherit them in Derived class. Nitin -- http://mail.python.org/mailman/listinfo/python-list
Variables with cross-module usage
Hello everyone, I am fairly new to Python and occasionally run into problems that are almost always resolved by referring to this mailing-list's archives. However, I have this one issue which has got me stuck and I hope you will be tolerant enough to help em out with it! What I want to achieve is something like the global variables in C/C++: you declare them in one file and "extern" them in all the files where you need to use them. I have 3 files: one.py, two.py and three.py as below: one.py -- a = 'place_a' b = 'place_b' x = 'place_x' myList = [a, b, 'place_c'] == two.py -- import one def myFunc(): print one.x print one.myList == three.py import one import two def argFunc(): one.x = 'place_no_x' one.a = 'place_no_a' one.b = 'place_no_b' if __name__ == '__main__': two.myFunc() print argFunc() two.myFunc() == Output: --- 'place_x' ['place_a', 'place_b', 'place_c'] 'place_no_x' ['place_a', 'place_b', 'place_c'] (*** instead of ['place_no_a', 'place_no_b', 'place_c'] ***) The last line in the output is what's baffling me. Can anyone please help me know if I am doing something wrong? Thanks in advance, Nitin. -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables with cross-module usage
Thanks for the reply MRAB, Rami, Matt and Mel, I was assuming that since one.myList0] = one.a, the change in one.a will ultimately trickle down to myList[0] whenever myList[0] is printed or used in an expression. It doesn't come intuitively to me as to why that should not happen. Can you kindly suggest what is the correct way to go about it? Nitin. > > > > > Hi Nitin, > > > > On Sat, Nov 28, 2009 at 14:36, MRAB wrote: > >> Nitin Changlani. wrote: > >>> three.py > >>> > >>> import one > >>> import two > >>> > >>> def argFunc(): > >>> one.x = 'place_no_x' > >>> one.a = 'place_no_a' > >>> one.b = 'place_no_b' > >>> > > > > I think this is what is biting you. You might expect that after > > argFunc, one.x would be set to 'place_no_x' and so on. However, > > Python's scoping doesn't work like that -- the name one.x is only > > rebound in the function's scope, so outside of argFunc (e.g. in your > > main printing code) one.x is still bound to 'place_x'. > > No, It's not like that. MRAB had it. The thing is, that when one.py is > imported, it sets the name one.a to refer to a string 'place_a'. Then a > list named one.myList is built with one.myList[0] referring to the same > string as one.a . So far, so good. > > Then the function argFunc is called. It uses `one` as a name from its > global namespace. Inside argFunc, the names one.x and one.a are rebound to > different strings from the ones they started with. *But* one.myList[0] > isn't touched, and still refers to 'place_x' like it always did. > >Mel. > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables with cross-module usage
Thanks for the reply MRAB, Rami, Matt and Mel, I was assuming that since one.myList0] = one.a, the change in one.a will ultimately trickle down to myList[0] whenever myList[0] is printed or used in an expression. It doesn't come intuitively to me as to why that should not happen. Can you kindly suggest what is the correct way to go about it? Nitin. -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables with cross-module usage
Thanks Dennis and Steve, This explains it all! I will discard using one.a and use one.myList[0] directly, instead. I really appreciate your patience and the elaboration of the concept. Warm Regards, Nitin Changlani. On Sun, Nov 29, 2009 at 1:02 AM, Steven D'Aprano < st...@remove-this-cybersource.com.au> wrote: > On Sat, 28 Nov 2009 22:18:11 -0500, Nitin Changlani wrote: > > > Thanks for the reply MRAB, Rami, Matt and Mel, > > > > I was assuming that since one.myList0] = one.a, the change in one.a will > > ultimately trickle down to myList[0] whenever myList[0] is printed or > > used in an expression. It doesn't come intuitively to me as to why that > > should not happen. Can you kindly suggest what is the correct way to go > > about it? > > > You are confusing *names* and *objects*. The presence or absence of a > module qualifier is irrelevant, so for simplicity I will avoid it. I will > use ` ` quotation marks to refer to names, to avoid confusing them with > strings. > > > The Python statement > > a = "some text" > > creates a name `a` which is bound to the object "some text". > > myList[0] = a > > stores the object bound to the name `a` to the first position of myList, > not the name itself. So myList[0] ends up being "some text", but it has > no idea whether it came from the name `a` or somewhere else. > > Then when you execute: > > a = "different text" > > the name `a` is bound to the object "different text". But this doesn't > affect myList[0] at all, because you're not changing the object "some > text" -- strings are immutable and can't be changed. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > > Thanks for the reply MRAB, Rami, Matt and Mel, > > I was assuming that since one.myList0] = one.a, the change in one.a will > ultimately trickle down to myList[0] whenever myList[0] is printed or used > in an expression. It doesn't come intuitively to me as to why that should > not happen. Can you kindly suggest what is the correct way to go about it? > First you understand that no common programming language behaves this way... It's not just Python. It's just more subtle in Python. In classical languages "one.myList[0]" represents a location (in this case, think of a room of file cabinets). "one" is a cabinet in the room; myList is a drawer in the cabinet; [0] is a folder in the drawer. and "a" is another drawer. In this classical language "one.myList[0] = one.a" means "open up the drawer a in cabinet one, make a COPY of what it contains, and put that copy into the [0] folder inside drawer myList in cabinet one. In these languages, the names always refer to the same location. Python confuses matters by having names that don't really refer to location, but are attached to the objects. "one" is a name attached to an object (the module). "a" is a name "inside" the object "one" which is attached to some other object, whatever it is. Similarly, "myList" is a name attached to an object (an indexed list or a keyed dictionary). "[0]" is a "name" (the index or key) into the object the name "myList" is attached to. "one.myList[0] = one.a" means "find the object with the name 'one.a' attached to it, and attach then name 'one.myList[0]' to the same object" Later, if you do "one.a = something", you say "find the object with name 'something' and attach the name 'one.a' to it" -- it is, in effect, the name that is moved from object to object -- no copy is made. -- Wulfraed Dennis Lee Bieber KD6MOG wlfr...@ix.netcom.com HTTP://wlfraed.home.netcom.com/<http://wlfraed.home.netcom.com/> -- http://mail.python.org/mailman/listinfo/python-list
Re: packaging python code in zip file
have u tried using setuptools and distutils they are used for python package distributions On Thu, Dec 9, 2010 at 5:02 PM, mark jason wrote: > hi, > I have created a python app in eclipse pydev .The app is structured as > below.. > > mypackage > |__ __init__.py > |__ driver.py > |__ helper.py > |__ utils.py > > The driver.py has the main program.I have added if > __name__=="__main__" block in the > > driver.py and pydev's run configuration has the following values, > Project : myproject > Main Module :${workspace_loc:myproject/src/mypackage/driver.py} > So,the app runs in pydev without any problems. > > Then I thought of providing the modules as a zip file.So I created a > zip file containing > mypackage directory.The user should be able to unzip the zip file and > run the application from command line . > > What bothers me is that ,the user will have to cd to mypackage folder > and run python driver.py.. > This doesn't look like the proper way.. > I also thought of putting the driver,helper,utils modules in a folder > called mycode and zipping it without the __init__.py file . > I am not sure which is the correct way. > Can somebody advise me as to how I can package it better? > > thanks, > > mark > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: python-parser running Beautiful Soup needs to be reviewed
try using lxml ... its very useful On Sat, Dec 11, 2010 at 11:24 AM, Martin Kaspar wrote: > Hello commnity > > i am new to Python and to Beatiful Soup also! > It is told to be a great tool to parse and extract content. So here i > am...: > > I want to take the content of a -tag of a table in a html > document. For example, i have this table > > > > > This is a sample text > > > > This is the second sample text > > > > > How can i use beautifulsoup to take the text "This is a sample text"? > > Should i make use > soup.findAll('table' ,attrs={'class':'bp_ergebnis_tab_info'}) to get > the whole table. > > See the target > http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323 > > Well - what have we to do first: > > The first thing is t o find the table: > > i do this with Using find rather than findall returns the first item > in the list > (rather than returning a list of all finds - in which case we'd have > to add an extra [0] > to take the first element of the list): > > > table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) > > Then use find again to find the first td: > > first_td = soup.find('td') > > Then we have to use renderContents() to extract the textual contents: > > text = first_td.renderContents() > > ... and the job is done (though we may also want to use strip() to > remove leading and trailing spaces: > > trimmed_text = text.strip() > > This should give us: > > > print trimmed_text > This is a sample text > > as desired. > > > What do you think about the code? I love to hear from you!? > > greetings > matze > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: O'Reilly Python Certification
Can someone provide any links or any starting points on how to apply and what are the prerequisites Thanks, Nitin On Thu, Dec 16, 2010 at 12:18 PM, Steve Holden wrote: > On 12/15/2010 4:21 PM, Stefan Sonnenberg-Carstens wrote: > > Am 15.12.2010 22:11, schrieb Steve Holden: > >> On 12/15/2010 3:40 PM, Tim Chase wrote: > >>> On a more serious note, it would be interesting to know if it's > possible > >>> to test out of the certification for those of us that have been using > >>> Python for a long time. > >> That's an interesting idea - let a bunch of experienced Python users > >> tell me what a lousy job I have done of explaining the language. :) > >> > >> Seriously, I would be interested, and it's a terrific idea. I can't do > >> anything before January, but if anyone is interested in taking part in > >> such a review of the materials I'd be grateful if they would contact me > >> privately by email on a "no promises" basis. > >> > >> regards > >> Steve > > I think he meant: take the test without study first. > > I'd be interested in both, though. > > > There isn't a test. The award of the certificate is based on providing > working solutions to projects at the end of each lesson. > > Bear in mind I have not spoken to my O'Reilly contacts about whether > they would be OK with such a scheme, hence the "no promises". > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ > See Python Video! http://python.mirocommunity.org/ > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: lxml etree question
On Fri, Dec 24, 2010 at 8:40 PM, Jim wrote: > Hello, I wonder if someone knows about lxml.etree and namespaces? > > I want to build an ElementTree where some of the sub-elements have > attributes that serialize this way. > > .. > > I've tried just comment_elet.set('xml:lang','de') and it didn't like > that at all (although it takes comment_elet.set('auth:id','jones') > just fine). I've also spelunked the docs and googled but have not hit > on the right invocation. If someone knows, I'd be grateful. > > Jim > -- > http://mail.python.org/mailman/listinfo/python-list > You can check this http://codespeak.net/pipermail/lxml-dev/2006-February/000920.html -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Graphing API,
you can check pywebgraph On Wed, Jan 5, 2011 at 3:49 PM, Slie wrote: > Is there a graphing API, someone suggests? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: trouble installing MySQLdb (cygwin) + Bonus question
Nothing againest mysqlDB but I had tried using it sometimes and found it little difficult to use when you left the connections open idle for sometime . I had used PySQLPool then to solve my issues. Give it a try, I would recommend it. Thanks, nitin On Tue, Jan 25, 2011 at 8:35 PM, Matthew Roth wrote: > On Jan 25, 4:30 am, Dennis Lee Bieber wrote: > > On Mon, 24 Jan 2011 14:25:09 -0800 (PST), Matthew Roth > > declaimed the following in > > gmane.comp.python.general: > > > > > > > > > I've explored various avenues all day to no avail. Can anyone offer a > > > solution or a direction to work towards. One avenue was ignorning the > > > check for posix, and having it run setup_windows, but this just brings > > > in problems with _winreg(?) seeing how I have a posix version of > > > python through cygwin. > > > > Maybe you need the development headers for MySQL? > -- > I do believe I have them. Perhaps I need to find the correct way to > point to them. > I believe it is looking for the dev headers for a linux client when I > am using a client for windows via cygwin. > > Or perhaps I should look into installing a separate linux mysql client > in cygwin. > I read of a similiar problem with perl, but the documentation felt a > bit dated and several steps would no longer function correctly. > > > > > > Lastly, for the bonus question. > > > Why MySQLdb why not something like this: > > > -- > > > import os > > > cmd = 'mysql -uroot -pxxx db -e "SELECT * FROM tblxxx;"' > > > os.system(cmd) > > > > Passing username/password to a shell command that might be parsed > by > > some outside process? Security leak! > -- > I do indeed see that. However, all my python calls will be done within > my local intranet. > But is this a reason to not use os module at all? fetching a > dirlisting or mkdir is still > a valid reason to use the os Module, correct? > > > > Second -- MySQL is a server model DBMS; it doesn't have to be on > the > > local machine. > -- > unfortunately, for my use it does. We do have an old centOs box here, > but the mysql running on that is severely outdated and so too is the > python. > I have been discouraged from upgrading the former, and the latter I > was told only if I could do it through yum. Making an altinstall form > source seems to be > discouraged. Good news is I think they have decided to upgrade our > development box. > > > > Third -- ever heard of TRANSACTIONS? How would you handle a > > transaction if every SQL statement was a totally independent process? > > -- > No. quite to my embarrassment I haven't. But this is not to say I have > not used them. It sounds as if I have. > But, you can put more than one sql statement into a cmdline. > mysql = "mysql -uuser -ppass db -e \"SELECT CURTIME(); > CREATE TABLE tempTBL ( > freq INT, > x INT, > y VARCHAR(255), > PRIMARY KEY(x, y); > > LOAD XML INFLE 'doc' > INTO TABLE tempTBL > ROWS IDENTIFIED BY ''; > > INSERT INTO freqTbl(x,y,freq) > SELECT x,y,freq FROM tempTBL > ON DUPLICATE KEY UPDATE freq=tempTbl.freq+freqTbl.freq; > > SELECT CURTIME();\" > os.system(mysql) > > I haven't tested that, but I know it works at the command line. > I do fully intend to use MySQLdb through python and conduct more of > the processing and parsing in python. It will be a learning > experience. I have a background in anthropology, not computer science. > But I love learning all this, and love that my place of employment > encourages me to learn this. Unfortunately with self-learning you can > sometimes miss out on important concepts and still accomplish tasks. > > Thank you for your reply. > > > > Wulfraed Dennis Lee Bieber AF6VN > > wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Would like to add an "upload" facility to my web site
On Mon, Jan 31, 2011 at 11:16 PM, Google Poster wrote: > On Jan 31, 11:36 am, Luis M. González wrote: > > On Jan 31, 1:50 pm, Ramon F Herrera wrote: > > > > > > > > > On Jan 31, 10:49 am, Ramon F Herrera wrote: > > > > > > (newbie alert) > > > > > > This is what I have so far: > > > > > >http://patriot.net/~ramon/upload_facility.html > > > > > > The code is shown below. It seems I need that actual script that > > > > performs the file transfer. I would prefer it in Python. > > > > > > TIA, > > > > > > -Ramon > > > > > > --- > > > > > > > > > > > > > > > > > > > > > > Name of file to be uploaded: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > IMPORTANT Bonus question: > > > > > Where should I post this type of question about writing stuff for the > > > web > > > > > -Ramon > > > > I guess this question is framework specific. > > Are you using any framework (django, pylons, etc...)? > > > Luis, > > Allow me to make this more clear. I have my own servers, all of them > running Linux. I have been Linux sysadmin for more time than I care to > remember. However, I (on purpose) provided an example hosted at my > commercial shell provider. That was a deliberate decision, because I > am looking for the simplest possible solution. > > I guess the question now is: Do I need root access to uploads files?? > > Gracias, > > -Ramon > > -- > You don't need a root access to upload files. You will just need to create a directory where you want to save the uploaded files and grant permission to the username by which the web server is running. In case the file uploads are small the simple upload feature works fine but for larger files you may need to write a chunk read/write api > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie getting desperate with for
can you share the first line of your shell (shabang) ? I think you have forgotten to tell the shell which interpreter to use if you have not put #!/usr/bin/python then its plain shell script which is incorrect On Thu, Feb 17, 2011 at 1:57 PM, Werner wrote: > I have a trivially simple piece of code called timewaster.py: > > > while True: >i = 0 >for i in range(10): >break > _ > > It runs fine with Eric but when I try to run it from shell... > > ./timewaster.py > ./timewaster.py: line 4: syntax error near unexpected token `(' > ./timewaster.py: line 4: `for i in range(10):' > > I've tried this on openSuse 11.3 and Kubuntu 10.04, both use Python > version 2.6.5, both show the above. > > Before I tear out my hair any more (only 3 left) I thought I'd ask here > what I am doing wrong. > > Best Regards > Werner Dahn > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Python fails on math
You may want to restrict the result to certain limit in the floating numbers each system has its own levels of floating numbers and even a small difference is a difference to return FALSE On Tue, Feb 22, 2011 at 6:50 PM, christian schulze wrote: > Hey guys, > > I just found out, how much Python fails on simple math. I checked a > simple equation for a friend. > > [code] > >>> from math import e as e > >>> from math import sqrt as sqrt > >>> 2*e*sqrt(3) - 2*e == 2*e*(sqrt(3) - 1) > False > [/code] > > So WTF? The equation is definitive equivalent. (See > http://mathbin.net/59158) > > PS: > > #1: > >>> 2.0 * e * sqrt(3.0) - 2.0 * e > 3.9798408154464964 > > #2: > >>> 2.0 * e * (sqrt(3.0) -1.0) > 3.979840815446496 > > I was wondering what exactly is failing here. The math module? Python, > or the IEEE specifications? > > -- > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Netbeans plugin and Python 3
Hi, I never tried python3.0 with netbeans but I use python 2.6.5 with netbean 6.7.1 Here is how I managed to change from python 2.5 (netbeans default) to 2.6.5 1) From the tools-> plugins section install python plugin 2) Once plugin is installed just restart netbeans so that plugin is activated 3) After plugin is activated, you can edit default python version by tools-> python platform 4) It will open a configure window, where you can point python to newly installed 3.0 version. I hope that helps. Thanks, nitin On Fri, Jul 9, 2010 at 9:30 PM, wrote: > Send Python-list mailing list submissions to >python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, visit >http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to >python-list-requ...@python.org > > You can reach the person managing the list at >python-list-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. python instructor (Greg) > 2. Re: ipython problem in opening a file (Youngung Jeong) > 3. Netbeans plugin and Python 3 (Chrix) > 4. Re: python instructor (Ed Keith) > 5. Last day to submit your Surge 2010 CFP! (Jason Dixon) > 6. SqlAlchemy: remote connection on problem on mysql database (Massi) > 7. do (Robin) > 8. Re: Opinions please -- how big should a single module grow? > (Tomasz Rola) > 9. Re: Python -- floating point arithmetic (Aahz) > 10. Re: 'reload M' doesn't update 'from M inport *' (Aahz) > 11. Cpp + Python: static data dynamic initialization in *nix > shared lib? (Alf P. Steinbach /Usenet) > 12. Why there is no "setdefaultencoding" in sys module? (crow) > > > -- Forwarded message -- > From: Greg > To: python-list@python.org > Date: Fri, 9 Jul 2010 07:09:13 -0700 (PDT) > Subject: python instructor > We're looking for a first-rate python trainer to come to our > organization for a day or two. We are a small group of geospatial/ > remote sensing scientists whose research spans the gap between > environmental accounting/monitoring and policy and human interaction. > We have about 5-10 (or so) python users (and potential python users) > who could potentially apply new skills to several in-house projects. > The difficulty for the teacher would be covering breadth of experience > we have currently. > > Any thoughts or advice would be greatly appreciated. Thanks very > much, > > Greg > > > > -- Forwarded message -- > From: Youngung Jeong > To: Eli Bendersky > Date: Fri, 9 Jul 2010 23:27:08 +0900 > Subject: Re: ipython problem in opening a file > Thanks a lot! > > Youngung > > > On Fri, Jul 9, 2010 at 10:17 PM, Eli Bendersky wrote: > >> On Fri, Jul 9, 2010 at 16:07, Youngung Jeong >> wrote: >> > Thank you for your kindness. >> > I found you're right. It's running in that folder. >> > What should I do for making this work? >> > Could you please tell me a bit more... >> > >> > Youngung >> >> You can change the "current directory" ipython executes in, by either >> executing it directly (from the command line) in the directory of your >> choice, or calling the os.chdir function with the path of your choice. >> >> Eli >> > > > > -- Forwarded message -- > From: Chrix > To: python-list@python.org > Date: Fri, 9 Jul 2010 07:26:24 -0700 (PDT) > Subject: Netbeans plugin and Python 3 > Hi, > > Someone knows if Netbeans will support Python 3 language features? > Nowadays, I tried Netbeans 6.9 but it only supports Python 2.5 :( > And I'd like really to develop with Python 3. > > Thanks. > > > > -- Forwarded message -- > From: Ed Keith > To: python-list@python.org, Greg > Date: Fri, 9 Jul 2010 07:49:05 -0700 (PDT) > Subject: Re: python instructor > Where are you located? > > -EdK > > Ed Keith > e_...@yahoo.com > > Blog: edkeith.blogspot.com > > > --- On Fri, 7/9/10, Greg wrote: > > > From: Greg > > Subject: python instructor > > To: python-list@python.org > > Date: Friday, July 9, 2010, 10:09 AM > > We're looking for a first-rate python > > trainer to come to our > > organization for a day or two. We are a small group > > of geospatial/ > > remote sensing scientists whose research spans the gap > > between > > environmental accounting/monitoring and policy an
Re: Is python suitable for my needs?
Python will absolutely will suit for monitoring. I use it on tomcat, mysql , apache and linux as well as freebsd Thanks, Nitin On Thu, Jul 15, 2010 at 1:06 PM, Simon SSt wrote: > Hi, > > Never too late to discover a new language :-) > > I hope anybody could help me answering my questions. I'm a technical > consultant for a software editor. Our software is running on the UNIX > (solaris 10 / AIX 5L), Sybase 15.x / Oracle 10G , Weblogic Server 9.x and > 10.x. > > I'd like to know if Python is suitable for helping me: > Monitoring the UNIX box? > Get some metrics from Sybase and Oracle? > Get JMX metrics from Weblogic Server (Weblogic Server is provided with a > scripting tool based on Jython) > > Thanks for your hints. > > Simon > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Accumulate function in python
Hi, you may want to do like this array=[0,1,2] sumArray = [] for element in range(0,len(array)): if element == 0 : sumArray.append(array[element]) else: sumArray.append((array[element] + sumArray[element-1])) and then you can recheck it Thanks, nitin On Mon, Jul 19, 2010 at 4:48 PM, dhruvbird wrote: > Hello, > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > What is the best way (or pythonic way) to get this. > > Regards, > -Dhruv. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Urrlib2 IncompleteRead error
Hi, Check if the webpage you are trying to access is redirecting the page to some other page? or the timeout is too less for the request to finish Thanks, Nitin On Tue, Jul 27, 2010 at 7:30 PM, dirknbr wrote: > I am running urllib2.request and get this response when I do the read. > Any ideas what causes this? > > return response.read() > File "C:\Python26\lib\socket.py", line 329, in read >data = self._sock.recv(rbufsize) > File "C:\Python26\lib\httplib.py", line 518, in read >return self._read_chunked(amt) > File "C:\Python26\lib\httplib.py", line 561, in _read_chunked >raise IncompleteRead(''.join(value)) > IncompleteRead: IncompleteRead(3235 bytes read) > > Dirk > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Urrlib2 IncompleteRead error
import socket # timeout in seconds timeout = 10 socket.setdefaulttimeout(timeout) On Tue, Jul 27, 2010 at 10:09 PM, Dirk Nachbar wrote: > Thanks, I don't think it's redirecting, how can I increase the timeout? > > > On 27 July 2010 16:56, Nitin Pawar wrote: > >> Hi, >> >> Check if the webpage you are trying to access is redirecting the page to >> some other page? >> or the timeout is too less for the request to finish >> >> >> Thanks, >> Nitin >> >> On Tue, Jul 27, 2010 at 7:30 PM, dirknbr wrote: >> >>> I am running urllib2.request and get this response when I do the read. >>> Any ideas what causes this? >>> >>> return response.read() >>> File "C:\Python26\lib\socket.py", line 329, in read >>>data = self._sock.recv(rbufsize) >>> File "C:\Python26\lib\httplib.py", line 518, in read >>>return self._read_chunked(amt) >>> File "C:\Python26\lib\httplib.py", line 561, in _read_chunked >>>raise IncompleteRead(''.join(value)) >>> IncompleteRead: IncompleteRead(3235 bytes read) >>> >>> Dirk >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> >> >> >> -- >> Nitin Pawar >> >> > > > -- > http://twitter.com/dirknbr > http://maximum-likely.blogspot.com > > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: suitable py2app.
see if this helps http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html On Tue, Jul 27, 2010 at 11:06 PM, ata.jaf wrote: > Hi, > I'm looking for a suitable tutorial for "py2app". I googled it but > couldn't find anything. > Can you help me please? > Thanks > Ata > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: passing variables as object attributes
you would need to define a class first with its attiributes and then you may want to initiate the variables by calling the class initilializer On Mon, Aug 16, 2010 at 7:10 PM, Vikas Mahajan wrote: > Hello to all > > I am new to python. I am facing problem to use variables as object > attributes. I have to use loop and dynamically add attributes to a > object and for this purpose I have to use variables with object names. > > For example-: > Let us say object car has an attribute engine, then > varname = "engine" > car.varname = "dummy value" > is giving me Error: object car does not have attribute varname. > > Please tell me how can I use variables as objects attributes. > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't find elements using ElementTree find method
Try using getroot()<http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree.getroot> I think your root is components so its searching in root On Tue, Aug 31, 2010 at 2:19 PM, Brendan Simon (eTRIX) < brendan.si...@etrix.com.au> wrote: > I am trying to use ElementTree (with Python 2.7) and can't seem to find > elements at the top level. The find() and findall() methods seem to find > elements within the top level, but not if it the elements are at the top > level. > > How do I find top level elements ?? > Here is my code. > > import xml.etree.ElementTree as ET > > xml = '''\ > > > > Fred > Australia > > > ''' > > root = ET.fromstring( xml ) > > ### This pattern is not found :( > comps = root.find( './/components' ) > > ### These patterns are found ok :) > comp = root.find( './/component' ) > name = root.find( './/name' ) > > print 'comps =', comps > print 'comp =', comp > print 'name =', name > > > Thanks, Brendan. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: accessing a text file
may be something like this f = open ("file",r) data = f.read() f.close if word in data: print word, "is present in file" On Mon, Sep 6, 2010 at 3:17 AM, Baba wrote: > level: beginner > > how can i access the contents of a text file in Python? > > i would like to compare a string (word) with the content of a text > file (word_list). i want to see if word is in word_list. let's assume > the TXT file is stored in the same directory as the PY file. > > def is_valid_word(word, word_list) > > > thanks > Baba > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: How to Convert IO Stream to XML Document
try using parse from string ... and try minidom.parse(StringIO.StingIO(string)).documentElement On Fri, Sep 10, 2010 at 9:50 PM, jakecjacobson wrote: > I am trying to build a Python script that reads a Sitemap file and > push the URLs to a Google Search Appliance. I am able to fetch the > XML document and parse it with regular expressions but I want to move > to using native XML tools to do this. The problem I am getting is if > I use urllib.urlopen(url) I can convert the IO Stream to a XML > document but if I use urllib2.urlopen and then read the response, I > get the content but when I use minidom.parse() I get a "IOError: > [Errno 2] No such file or directory:" error > > THIS WORKS but will have issues if the IO Stream is a compressed file > def GetPageGuts(net, url): >pageguts = urllib.urlopen(url) >xmldoc = minidom.parse(pageguts) >return xmldoc > > # THIS DOESN'T WORK, but I don't understand why > def GetPageGuts(net, url): >request=getRequest_obj(net, url) >response = urllib2.urlopen(request) >response.headers.items() >pageguts = response.read() ># Test to see if the response is a gzip/compressed data stream >if isCompressedFile(response, url): >compressedstream = StringIO.StringIO(pageguts) >gzipper = gzip.GzipFile(fileobj = compressedstream) >pageguts = gzipper.read() >xmldoc = minidom.parse(pageguts) >response.close() >return xmldoc > > # I am getting the following error > Starting SiteMap Manager ... > Traceback (most recent call last): > File "./tester.py", line 267, in ? >main() > File "./tester.py", line 49, in main >fetchSiteMap(ResourceDict, line) > File "./tester.py", line 65, in fetchSiteMap >pageguts = GetPageGuts(ResourceDict['NET'], url) > File "./tester.py", line 89, in GetPageGuts >xmldoc = minidom.parse(pageguts) > File "/usr/lib/python2.4/xml/dom/minidom.py", line 1915, in parse >return expatbuilder.parse(file) > File "/usr/lib/python2.4/xml/dom/expatbuilder.py", line 922, in > parse >fp = open(file, 'rb') > IOError: [Errno 2] No such file or directory: ' encoding="UTF-8"?>\nhttp://www.sitemaps.org/ > schemas/sitemap/0.9">\n\nhttp://www.myorg.org/janes/ > sitemaps/binder_sitemap.xml\n2010-09-09\n sitemap>\n\nhttp://www.myorg.org/janes/sitemaps/ > dir_sitemap.xml\n2010-05-05\n > \n\nhttp://www.myorg.org/janes/sitemaps/ > mags_sitemap.xml\n2010-09-09\n > \n\nhttp://www.myorg.org/janes/sitemaps/ > news_sitemap.xml\n2010-09-09\n > \n\nhttp://www.myorg.org/janes/sitemaps/ > sent_sitemap.xml\n2010-09-09\n > \n\nhttp://www.myorg.org/janes/sitemaps/ > srep_sitemap.xml\n2001-05-04\n > \n\nhttp://www.myorg.org/janes/sitemaps/yb_sitemap.xml loc>\n2010-09-09\n\n\n' > > # A couple of supporting things > def getRequest_obj(net, url): >request = urllib2.Request(url) >request.add_header('User-Agent', 'ICES Sitemap Bot dni-ices- > searchad...@ugov.gov') >request.add_header('Accept-encoding', 'gzip') >return request > > def isCompressedFile(r, u): >answer=False >if r.headers.has_key('Content-encoding'): >answer=True >else: ># Check to see if the URL ends in .gz >if u.endswith(".gz"): >answer=True >return answer > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: python call a procedure at the specified time
are you looking for something like cron? On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: > Hi, > I have a python script running behind the scene,and I need it to call a > method on sunday 9 o'clock. > I get an idea,that I get the current time,and calculate the seconds to > sunday 9 o'clock, > then sleep these seconds and call my method,I think there could be an > elegant way to resolve this. > > Regards, > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: python call a procedure at the specified time
I think to do so either you will need to schedule a cron or write a daemon process which will run continuously. Assuming that its running only once a day or say timely manner daemon will be a costly affair for system resources To schedule crons for python, this might be useful (using yaml) http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml Thanks, Nitin On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: > Hi Nitin,I need a python solution for that. > > > On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: > >> are you looking for something like cron? >> >> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >> >>> Hi, >>> I have a python script running behind the scene,and I need it to call a >>> method on sunday 9 o'clock. >>> I get an idea,that I get the current time,and calculate the seconds to >>> sunday 9 o'clock, >>> then sleep these seconds and call my method,I think there could be an >>> elegant way to resolve this. >>> >>> Regards, >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >>> >> >> >> -- >> Nitin Pawar >> >> > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: python call a procedure at the specified time
cron is daemon running which maps the tasks with the frequency if you want to run a task at a specific time, you can schedule it for the same if you need any help, ping on gtalk, can help you out Thanks, Nitin On Wed, Sep 15, 2010 at 1:05 PM, Von wrote: > I have read the cron man page just now,It says that cron wakes up every > minute to check task. > I will try install/uninstall with cron. > > Cheers, > > > On Wed, Sep 15, 2010 at 3:25 PM, Von wrote: > >> Thanks Nitin,I wonder how cron works,does it create a timer thread for >> each task? >> >> >> On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar wrote: >> >>> I think to do so either you will need to schedule a cron or write a >>> daemon process which will run continuously. >>> Assuming that its running only once a day or say timely manner daemon >>> will be a costly affair for system resources >>> >>> To schedule crons for python, this might be useful (using yaml) >>> >>> http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml >>> >>> Thanks, >>> Nitin >>> >>> >>> On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: >>> >>>> Hi Nitin,I need a python solution for that. >>>> >>>> >>>> On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar >>>> wrote: >>>> >>>>> are you looking for something like cron? >>>>> >>>>> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >>>>> >>>>>> Hi, >>>>>> I have a python script running behind the scene,and I need it to call >>>>>> a method on sunday 9 o'clock. >>>>>> I get an idea,that I get the current time,and calculate the seconds to >>>>>> sunday 9 o'clock, >>>>>> then sleep these seconds and call my method,I think there could be an >>>>>> elegant way to resolve this. >>>>>> >>>>>> Regards, >>>>>> >>>>>> -- >>>>>> http://mail.python.org/mailman/listinfo/python-list >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> Nitin Pawar >>>>> >>>>> >>>> >>> >>> >>> -- >>> Nitin Pawar >>> >>> >> > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: scheduler or infinite loop
why not schedule cron */5 * * * * and check in your code that previous execution was successful or not On Wed, Sep 29, 2010 at 5:29 PM, harryos wrote: > hi > I am trying to write a program to read data from a site url. > The program must read the data from site every 5 minutes. > > def get_data_from_site(pageurlstr): >h=urllib.urlopen(pageurlstr) >data=h.read() >process_data(data) > > At first, I thought of using the sched module ,but then it doesn't > look right adding so many scheduler.enter() statements.The program is > supposed to execute the above function every > 5 minutes until the application is shut down by the user. > > I created an infinite loop > while True: >print time.asctime() >get_data_from_site('http://somesite.com/') >time.sleep(300) > > Is there a better way to do this?Any suggestions ,pointers most > welcome > thanks > harry > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Help on formatting xml document
use minidom to parse from string and then write it to a file from xml.dom.minidom import parse, parseString parseString(rawdata) On Mon, Oct 4, 2010 at 11:33 AM, Santosh Mohan wrote: > Hi, > > Need help in formatting xml document using xml.doc.minidom > > > I have a raw xml output, I need to format the xml output and write it to a > file. > > > rawdata="""Santosh 29 > Bangalore """ > > I would appreciate your help. > > Thanks, > Santosh > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: how to write an xml file without dom.ext?
why not just convert it to string with print pretty and then normal write to a file On Thu, Oct 7, 2010 at 3:36 PM, hackingKK wrote: > Hello all. > I need to create an xml file. > I am using dom.minidom module. > It works fine as long as the xml tree is created. > But I get the import error for dom.ext. > I searched through the python docs but can't find a solution. > I am pritty sure that there is way to write the file to disk without using > the ext module. > Since there are so many software doing this with python 2.6 I am sure it > works. > So can some one tell me if there is a way to avoide ext and prittyprint and > still write a file to the disk? > > Happy hacking. > Krishnakant. > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: how to write an xml file without dom.ext?
import xml.dom.minidom import os xml = xml.dom.minidom.parse(xml_fname) # or xml.dom.minidom.parseString(xml_string) pretty_xml_as_string = xml.toprettyxml() file = open("newfile", 'w') file.write(pretty_xml_as_string) file.close() 1. On Thu, Oct 7, 2010 at 4:16 PM, hackingKK wrote: > On Thursday 07 October 2010 03:49 PM, Nitin Pawar wrote: > > why not just convert it to string with print pretty and then normal write > to a file > > > Can you give an example. > > happy hacking. > Krishnakant. > > On Thu, Oct 7, 2010 at 3:36 PM, hackingKK wrote: > >> Hello all. >> I need to create an xml file. >> I am using dom.minidom module. >> It works fine as long as the xml tree is created. >> But I get the import error for dom.ext. >> I searched through the python docs but can't find a solution. >> I am pritty sure that there is way to write the file to disk without using >> the ext module. >> Since there are so many software doing this with python 2.6 I am sure it >> works. >> So can some one tell me if there is a way to avoide ext and prittyprint >> and still write a file to the disk? >> >> Happy hacking. >> Krishnakant. >> >> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Nitin Pawar > > > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: 2D List
the declaration is wrong if you want to create a two dimensional array try to use functions like arange and reshape On Mon, Oct 11, 2010 at 9:54 PM, Fasihul Kabir wrote: > a = [0]*5 > for i in range(0, 4): > for j in range(0, i): > a[i].append(j) > > why the above codes show the following error. and how to overcome it. > > Traceback (most recent call last): > File "", line 3, in > a[i].append(j) > AttributeError: 'int' object has no attribute 'append' > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: parse xml
this is wrong xml.dom.minidom.parseString("boolean_width.xml") ... if u r parsing from String use string variable as argument or use parse only if parsing from file On Sat, Oct 16, 2010 at 12:07 AM, Andreas Waldenburger wrote: > On Fri, 15 Oct 2010 10:49:18 -0700 (PDT) kostia > wrote: > > > I have xml file: > > > > > > 5 > > > > > > I want to get the value of n (= 5) inside my python program, I'm > > doing this: > > > > import xml.dom.minidom > > from xml.dom.minidom import Node > > doc = xml.dom.minidom.parseString("boolean_width.xml") > > n = doc.getElementsByTagName("root")[0].firstChild.nodeValue.strip() > > print n > > > > and it is failed. [snip] > > How? What's the error message? > > -- > To reach me via email, replace INVALID with the country code of my home > country. But if you spam me, I'll be one sour Kraut. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Python3: Is this a bug in urllib?
the content is in a loop because it is getting redirected again and again and the interrupt exception is perfectly ok when you press ctrl +c On Tue, Oct 19, 2010 at 10:17 PM, Johannes Bauer wrote: > Hi, > > I've experienced the following behavior with Python3 of which I do not > know if it's a bug or not. On two Python3.1 implementations, Python's > urllib hangs when encountering a HTTP 301 (Redirect). > > The code to reproduce is a one-liner (actually, two-liner), Python from > Ubuntu tree: > > Python 3.1.2 (r312:79147, Apr 15 2010, 15:35:48) > [GCC 4.4.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> from urllib import request; request.URLopener().open("http://google.de > ") > > Also occurs on another Python version (Gentoo): > > Python 3.1.2 (release31-maint, Jun 9 2010, 23:58:21) > [GCC 4.3.4] on linux2 > > The exchanged HTTP is: > > GET http://google.de HTTP/1.1 > Accept-Encoding: identity > Host: google.de > User-Agent: Python-urllib/3.1 > > HTTP/1.1 301 Moved Permanently > Via: 1.1 IMMPWISA01 > Connection: Keep-Alive > Proxy-Connection: Keep-Alive > Content-Length: 218 > Expires: Thu, 18 Nov 2010 15:18:40 GMT > Date: Tue, 19 Oct 2010 15:18:40 GMT > Location: http://www.google.de/ > Content-Type: text/html; charset=UTF-8 > Server: gws > Cache-Control: public, max-age=2592000 > X-XSS-Protection: 1; mode=block > > content="text/html;charset=utf-8"> > 301 Moved > 301 Moved > The document has moved > http://www.google.de/";>here. > > > Although the content might indicate looping forever, it just hangs with > no web traffic whatsoever (the TCP connection stays open, however). > > When interrupting with Ctrl-C, this is the calltrace: > > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python3.1/urllib/request.py", line 1454, in open >return getattr(self, name)(url) > File "/usr/lib/python3.1/urllib/request.py", line 1628, in open_http >return self._open_generic_http(http.client.HTTPConnection, url, data) > File "/usr/lib/python3.1/urllib/request.py", line 1624, in > _open_generic_http >response.status, response.reason, response.msg, data) > File "/usr/lib/python3.1/urllib/request.py", line 1644, in http_error >return self.http_error_default(url, fp, errcode, errmsg, headers) > File "/usr/lib/python3.1/urllib/request.py", line 1648, in > http_error_default >void = fp.read() > File "/usr/lib/python3.1/socket.py", line 214, in readinto >return self._sock.recv_into(b) > KeyboardInterrupt > > Can anyone tell me if this is a bug or expected behavior? > > Regards, > Johannes > > -- > >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > > Zumindest nicht öffentlich! > Ah, der neueste und bis heute genialste Streich unsere großen > Kosmologen: Die Geheim-Vorhersage. > - Karl Kaos über Rüdiger Thomas in dsa > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: How on Factorial
focus on the AND condition ... return is true only if both conditions are true so unless the factorial is calculated (second portion of AND statement) return will not give factorial. the second portion is recursive call to self as long as x is greater than 1 On Wed, Oct 27, 2010 at 11:55 AM, Geobird wrote: > > I am a beginner in Python and would ask for a help. > > > I was searching for smaller version of code to calculate > factorial . Found this one > def fact(x): >return x > 1 and x * fact(x - 1) or 1 > > But I don't really get how ( x > 1 and x * fact(x - 1)) > works . > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: List index out of range, but list has enough elements
You may want to try a spilt if you are getting 8 different elements then it will give you a list of those elements On Tue, Nov 9, 2010 at 3:21 PM, Costin Gamenț wrote: > Thank you for your timely response. Yes, I am sure "i" and "j" are > from the same iteration. I should point out that "i" actually has 8 > elements and that str(i) gives a nice printout. > > On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel > wrote: > > Costin Gamenț, 09.11.2010 10:24: > >> > >> Hi, I am trying to read a string as csv, but I encountered an odd > >> problem. Here's my code: > >> > >>csvfile = csv.reader(datastr.split('\n'), delimiter=';') > >>r = '' > >>for i in csvfile: > >>for j in i: > >>print j > >>print i[0] > >> > >> the "print j" statement works, but "print i[0]" returns "IndexError: > >> list index out of range". Am I missing something? > > > > Are you sure the output you get from the "print j" is from the same loop > > iteration as the "print i[0]"? Try adding "i" to the output. > > > > Stefan > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: another newbie question
>From the error, you are importing wrong module which actually does not exists try importing something from maths On Sun, Nov 14, 2010 at 8:21 PM, otenki wrote: > Hello Pythonistas! > I'm trying to get floating point division to work; I'm using Python > 2.6.5. When I enter 'from _future_ import division' at the command > line, I get the ImportError, no module named _future_. How can I > rectify this? > Sorry for this basic question, but I don't know where else to turn. > Thanks, > Scott > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list