Multi Threading embedded python
Hello, I am embedding a python script in a C++ application. The script can be called simultaneously from multiple threads. What is the correct way to implement this situation: 1) Have unique python interpreter instantiations ( Py_Initialize() ) for each thread. 2) Have one python interpreter, and implement a lock on it so it can't be called simultaneously by multiple threads? Thanks Amit -- http://mail.python.org/mailman/listinfo/python-list
General questions about embedding Python.
Hello, I am currently studying how to embedd python. I am developing a graphical C++ application. My goal is to embedd python script that will control some kind of animation. I have some questions about python embedding: 1) Is there a good text book or other resource on embedding/extending? (I find it hard to learn only by the tutorial and C/Python API from the python.org site) 2) I have found that there are many ways to embedd a script: PyEvel_EvalCode() PyRun_SimpleFile() PyObject_CallObject() What are the cons and pros of using each of them? 3) Is there a problem with the PyRun_SimpleFile(). I am trying to run the following code: const char *SCRIPT_NAME = "C:\\test_script.py"; int _tmain(int argc, _TCHAR* argv[]) { Py_Initialize(); FILE *script_file; script_file = fopen(SCRIPT_NAME, "r"); if (script_file != NULL) PyRun_SimpleFile(script_file, SCRIPT_NAME); Py_Finalize(); return 0; } The python script has only one line: 'print "hello"' I build it with Python2.3 libraries. When I try to run the code I get access violation. 4) What is the correct way to handle/catch python exceptions in the embedding Python code? Forgive me if I have asked too many questions in one eMail, it is becuase I don't really know where to start learning this subject from. Thanks Amit -- http://mail.python.org/mailman/listinfo/python-list
Embedding performance.
Hello, Is there any kind of performance differences to the different ways of embedding python? PyEval_EvalCode() PyRun_SimpleFile() PyObject_CallObject() Thanks Amit -- http://mail.python.org/mailman/listinfo/python-list
BaseHTTPServer ThreadMixIn not working
Hi everyone, I am really stuck in a very simple problem and wanted to know if you could take some time to check it out - My code is simple. Using BaseHTTPServer and ThreadInMix I want to run a python script (Script1.py) for every request made simultaneously. My code-> from subprocess import PIPE, Popen from SocketServer import ThreadingMixIn from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler import time def simple_script(self): print 'simple_script' s = Popen('C:/Python27/python C:/Script1.py 5', shell=True, stdout=PIPE, stderr=PIPE) out, err = s.communicate() print out, err self.wfile.write(out) class Handler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.end_headers() self.wfile.write('{0}\n'.format(time.asctime())) simple_script(self) return class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): pass if __name__ == '__main__': server = ThreadedHTTPServer(('', 8080), Handler) print 'Starting server, use to stop' server.serve_forever() """ # C:/Script1.py import time, sys s = time.time() while True: if time.time() - s > int(sys.argv[1]): break else: time.sleep(1) print time.asctime() """ If I open multiple tabs/pages in Chrome/Firefox/IE and give URL: http://localhost:8080, the pages wait for previous page? This does not imply threading? Any help? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Make money to share your videos
Make money to share your videos Goodtolove.com is sharing their 50% adsense revenue with you to post videos of anything. Just keep up logging in and start posting now to make money... -- http://mail.python.org/mailman/listinfo/python-list
Simple Python Project Structure
Hi, I recently wrote a fairly complex project in python. It works great and it was completed fairly quickly thanks to python! Anyways, I am in the process of cleaning the code/directory and I had a simple question How do create my own modules and import them? Right now it works but they all have to be in the same directory. For example, project/ util/ config/ tests/ start.py I have a module in util/console.py, how do I import that. In start.py I have: from project.util.console import filetest but I get an ImportError. Thanks! Amit -- http://mail.python.org/mailman/listinfo/python-list
Calling multiple programs with subprocess
How does one go about calling multiple programs using subprocess? This is the program flow: C:\> wrenv.exe C:\> make clean .. .. The 'wrenv.exe' is necessary since it sets up the proper environment for building. How do I use subprocess to execute 'wrenv.exe' and then the 'make clean' command. Any help is appreciated. Thanks, Amit -- http://mail.python.org/mailman/listinfo/python-list
compilation problem of python on AIX 6.1
Hello I want to intsall python on my AIX 6.1 Box. I couldn't get any rpm for python 2.5.x for AIX 6.1. THen I decided to compile python 2.5.4 on my AIX box. I downloaded the python source code from www.python.org and tried to compile on my AIX both using gcc. step 1 ./configure --with-gcc configuration runs successfully step 2 make it gives me error case $MAKEFLAGS in *-s*) CC='gcc -pthread' LDSHARED='./Modules/ ld_so_aix gcc -pthread -bI:Modules/python.exp' OPT='-DNDEBUG -g - fwrapv -O3 -Wall -Wstrict-prototypes' ./python -E ./setup.py -q build;; *) CC='gcc -pthread' LDSHARED='./Modules/ld_so_aix gcc - pthread -bI:Modules/python.exp' OPT='-DNDEBUG -g -fwrapv -O3 -Wall - Wstrict-prototypes' ./python -E ./setup.py build;; esac running build running build_ext building 'bz2' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - Wstrict-prototypes -I. -I/avre/Python-2.5.4/./Include -I. -IInclude - I./Include -I/avre/Python-2.5.4/Include -I/avre/Python-2.5.4 -c /avre/ Python-2.5.4/Modules/bz2module.c -o build/temp.aix-6.1-2.5/avre/ Python-2.5.4/Modules/bz2module.o building '_tkinter' extension ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/ temp.aix-6.1-2.5/avre/Python-2.5.4/Modules/_tkinter.o build/ temp.aix-6.1-2.5/avre/Python-2.5.4/Modules/tkappinit.o -L/usr/X11/lib - ltk8.4 -ltcl8.4 -lX11 -o build/lib.aix-6.1-2.5/_tkinter.so *** WARNING: renaming "_tkinter" since importing it failed: 0509-022 Cannot load module build/lib.aix-6.1-2.5. 0509-026 System error: A file or directory in the path name does not exist. plz suggest -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] [RELEASED] Python 3.3.0
On Sat, Sep 29, 2012 at 10:18 PM, Georg Brandl wrote: > On behalf of the Python development team, I'm delighted to announce the > Python 3.3.0 final release. > > Python 3.3 includes a range of improvements of the 3.x series, as well > as easier porting between 2.x and 3.x. Major new features and changes > in the 3.3 release series are: > > * PEP 380, syntax for delegating to a subgenerator ("yield from") > * PEP 393, flexible string representation (doing away with the >distinction between "wide" and "narrow" Unicode builds) > * A C implementation of the "decimal" module, with up to 120x speedup >for decimal-heavy applications > * The import system (__import__) now based on importlib by default > * The new "lzma" module with LZMA/XZ support > * PEP 397, a Python launcher for Windows > * PEP 405, virtual environment support in core > * PEP 420, namespace package support > * PEP 3151, reworking the OS and IO exception hierarchy > * PEP 3155, qualified name for classes and functions > * PEP 409, suppressing exception context > * PEP 414, explicit Unicode literals to help with porting > * PEP 418, extended platform-independent clocks in the "time" module > * PEP 412, a new key-sharing dictionary implementation that >significantly saves memory for object-oriented code > * PEP 362, the function-signature object > * The new "faulthandler" module that helps diagnosing crashes > * The new "unittest.mock" module > * The new "ipaddress" module > * The "sys.implementation" attribute > * A policy framework for the email package, with a provisional (see >PEP 411) policy that adds much improved unicode support for email >header parsing > * A "collections.ChainMap" class for linking mappings to a single unit > * Wrappers for many more POSIX functions in the "os" and "signal" >modules, as well as other useful functions such as "sendfile()" > * Hash randomization, introduced in earlier bugfix releases, is now >switched on by default > > In total, almost 500 API items are new or improved in Python 3.3. > For a more extensive list of changes in 3.3.0, see > > http://docs.python.org/3.3/whatsnew/3.3.html Redirects to http://docs.python.org/py3k/whatsnew/3.3.html: 404 Not Found. Cheers, Amit. -- http://echorand.me -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] [RELEASED] Python 3.3.0
On Sat, Sep 29, 2012 at 10:37 PM, Dave Angel wrote: > On 09/29/2012 08:23 AM, Amit Saha wrote: >> On Sat, Sep 29, 2012 at 10:18 PM, Georg Brandl wrote: >>> >>> >>> For a more extensive list of changes in 3.3.0, see >>> >>> http://docs.python.org/3.3/whatsnew/3.3.html >> Redirects to http://docs.python.org/py3k/whatsnew/3.3.html: 404 Not Found. >> >> > Works for me. Perhaps a momentary glitch. Yes, I clicked too soon, i guess.. -Amit. -- http://echorand.me -- http://mail.python.org/mailman/listinfo/python-list
Re: Invalid syntax error
Its an indentation error -- A-M-I-T S|S -- http://mail.python.org/mailman/listinfo/python-list
MemoryError vs malloc error
Hi, I've a long running python process (running on freebsd). Sometimes when it uses too much memory it core dumps. I would've expected it to raise MemoryError. Normally, when would a python process raise MemoryError and when would it fail with malloc error and cores? This is happening in pure python code (Eg. if ' '.join(biglist)) etc. Regards, Amit -- http://mail.python.org/mailman/listinfo/python-list
indentation
Hello Group, i just start python is it necessary indentation in python ? thanks in advance ... -- http://mail.python.org/mailman/listinfo/python-list
Re: indentation
On Aug 11, 8:15 am, MRAB wrote: > On 11/08/2011 13:56, Amit Jaluf wrote:> Hello Group, > > i just start python is it necessary indentation in python ? > > Yes, indentation is part of the language. > > Even in programming languages where it isn't necessary, it's > recommended because it makes the code easier to read. Thanks MRAB which book or tutorial i should for it(Python) i found "A Byte of Python " by Swaroop after that which tutorial(book) i have to read Please Suggest me . -- http://mail.python.org/mailman/listinfo/python-list
about if __name == '__main__':
hello group i have one question about this if __name == '__main__': is it same as other languages like[c,c++] main function. because of i google and read faqs and also " http://docs.python.org/faq/programming#how-do-i-find-the-current-module-name"; this and i am confused. thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: about if __name == '__main__':
On Aug 28, 12:51 pm, Ian Kelly wrote: > On Sun, Aug 28, 2011 at 9:34 AM, Amit Jaluf wrote: > > hello group > > > i have one question about this > > > if __name == '__main__': sorry dear for this and thanks all of you for this -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing js/ajax in a sandboxed environment
On Sun, Feb 27, 2011 at 10:26 AM, Rohan Malhotra wrote: > BeautifulSoup library only fetches source of page. I need the access > to DOM after js execution with url as input parameter. > > Any pointers? > I am not sure but in case you need to make some ajax requests mechanize might help. http://wwwsearch.sourceforge.net/mechanize/ Please share the experience of what finally worked for you. -- A-M-I-T S|S -- http://mail.python.org/mailman/listinfo/python-list
Reference Cycles with instance method
Simple question. If I have the following code: class A: def __init__(self, s): self.s = s self.m2 = m1 def m1(self): pass if __name__ == '__main__': a = A("ads") a.m1() a = None The object is not garbage collected, since there appears to be a cycle (between method m2 and A). I would expect this to behave the same as having another method "def m2(self): self.m1()", but unfortunately its not. In above case m2 seems to be in a.__dict__ which is causing the cycle. Any idea why this is so? Regards, Amit -- http://mail.python.org/mailman/listinfo/python-list
Memory Usage of Strings
I'm observing a strange memory usage pattern with strings. Consider the following session. Idea is to create a list which holds some strings so that cumulative characters in the list is 100MB. >>> l = [] >>> for i in xrange(10): ... l.append(str(i) * (1000/len(str(i This uses around 100MB of memory as expected and 'del l' will clear that. >>> for i in xrange(2): ... l.append(str(i) * (5000/len(str(i This is using 165MB of memory. I really don't understand where the additional memory usage is coming from. If I reduce the string size, it remains high till it reaches around 1000. In that case it is back to 100MB usage. Python 2.6.4 on FreeBSD. Regards, Amit -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory Usage of Strings
sum(map(len, l)) => 8200 for 1st case and 9100 for 2nd case. Roughly 100MB as I mentioned. On Wed, Mar 16, 2011 at 11:21 PM, John Gordon wrote: > In Amit Dev > writes: > >> I'm observing a strange memory usage pattern with strings. Consider >> the following session. Idea is to create a list which holds some >> strings so that cumulative characters in the list is 100MB. > >> >>> l = [] >> >>> for i in xrange(10): >> ... l.append(str(i) * (1000/len(str(i > >> This uses around 100MB of memory as expected and 'del l' will clear that. > >> >>> for i in xrange(2): >> ... l.append(str(i) * (5000/len(str(i > >> This is using 165MB of memory. I really don't understand where the >> additional memory usage is coming from. > >> If I reduce the string size, it remains high till it reaches around >> 1000. In that case it is back to 100MB usage. > > I don't know anything about the internals of python storage -- overhead, > possible merging of like strings, etc. but some simple character counting > shows that these two loops do not produce the same number of characters. > > The first loop produces: > > Ten single-digit values of i which are repeated 1000 times for a total of > 1 characters; > > Ninety two-digit values of i which are repeated 500 times for a total of > 45000 characters; > > Nine hundred three-digit values of i which are repeated 333 times for a > total of 299700 characters; > > Nine thousand four-digit values of i which are repeated 250 times for a > total of 225 characters; > > Ninety thousand five-digit values of i which are repeated 200 times for > a total of 1800 characters. > > All that adds up to a grand total of 20604700 characters. > > Or, to condense the above long-winded text in table form: > > range num digits 1000/len(str(i)) total chars > 0-9 10 1 1000 1 > 10-99 90 2 500 45000 > 100-999 900 3 333 299700 > 1000- 9000 4 250 225 > 1-9 9 5 200 1800 > > grand total chars 20604700 > > The second loop yields this table: > > range num digits 5000/len(str(i)) total bytes > 0-9 10 1 5000 5 > 10-99 90 2 2500 225000 > 100-999 900 3 1666 1499400 > 1000- 9000 4 1250 1125 > 1-1 1 5 1000 1000 > > grand total chars 23024400 > > The two loops do not produce the same numbers of characters, so I'm not > surprised they do not consume the same amount of storage. > > P.S.: Please forgive me if I've made some basic math error somewhere. > > -- > John Gordon A is for Amy, who fell down the stairs > gor...@panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory Usage of Strings
Thanks Dan for the detailed reply. I suspect it is related to FreeBSD malloc/free as you suggested. Here is the output of running your script: [16-bsd01 ~/work]$ python strm.py --first USERPID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND amdev 6899 3.0 6.9 111944 107560 p0 S+9:57PM 0:01.20 python strm.py --first (python2.5) amdev 6900 0.0 0.1 3508 1424 p0 S+9:57PM 0:00.02 sh -c ps aux | egrep '\\<6899\\>|^USER\\>' amdev 6902 0.0 0.1 3380 1188 p0 S+9:57PM 0:00.01 egrep \\<6899\\>|^USER\\> [16-bsd01 ~/work]$ python strm.py --second USERPID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND amdev 6903 0.0 10.5 166216 163992 p0 S+9:57PM 0:00.92 python strm.py --second (python2.5) amdev 6904 0.0 0.1 3508 1424 p0 S+9:57PM 0:00.02 sh -c ps aux | egrep '\\<6903\\>|^USER\\>' amdev 6906 0.0 0.1 3508 1424 p0 R+9:57PM 0:00.00 egrep \\<6903\\>|^USER\\> (sh) Regards, Amit On Thu, Mar 17, 2011 at 3:21 AM, Dan Stromberg wrote: > > On Wed, Mar 16, 2011 at 8:38 AM, Amit Dev wrote: >> >> I'm observing a strange memory usage pattern with strings. Consider >> the following session. Idea is to create a list which holds some >> strings so that cumulative characters in the list is 100MB. >> >> >>> l = [] >> >>> for i in xrange(10): >> ... l.append(str(i) * (1000/len(str(i >> >> This uses around 100MB of memory as expected and 'del l' will clear that. >> >> >> >>> for i in xrange(2): >> ... l.append(str(i) * (5000/len(str(i >> >> This is using 165MB of memory. I really don't understand where the >> additional memory usage is coming from. >> >> If I reduce the string size, it remains high till it reaches around >> 1000. In that case it is back to 100MB usage. >> >> Python 2.6.4 on FreeBSD. >> >> Regards, >> Amit >> -- >> http://mail.python.org/mailman/listinfo/python-list > > On Python 2.6.6 on Ubuntu 10.10: > > $ cat pmu > #!/usr/bin/python > > import os > import sys > > list_ = [] > > if sys.argv[1] == '--first': > for i in xrange(10): > list_.append(str(i) * (1000/len(str(i > elif sys.argv[1] == '--second': > for i in xrange(2): > list_.append(str(i) * (5000/len(str(i > else: > sys.stderr.write('%s: Illegal sys.argv[1]\n' % sys.argv[0]) > sys.exit(1) > > os.system("ps aux | egrep '\<%d\>|^USER\>'" % os.getpid()) > > dstromberg-laptop-dstromberg:~/src/python-mem-use i686-pc-linux-gnu 10916 - > above cmd done 2011 Wed Mar 16 02:38 PM > > $ make > ./pmu --first > USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND > 1000 11063 0.0 3.4 110212 104436 pts/5 S+ 14:38 0:00 > /usr/bin/python ./pmu --first > 1000 11064 0.0 0.0 1896 512 pts/5 S+ 14:38 0:00 sh -c ps > aux | egrep '\<11063\>|^USER\>' > 1000 11066 0.0 0.0 4012 740 pts/5 S+ 14:38 0:00 egrep > \<11063\>|^USER\> > ./pmu --second > USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND > 1000 11067 13.0 3.3 107540 101536 pts/5 S+ 14:38 0:00 > /usr/bin/python ./pmu --second > 1000 11068 0.0 0.0 1896 508 pts/5 S+ 14:38 0:00 sh -c ps > aux | egrep '\<11067\>|^USER\>' > 1000 11070 0.0 0.0 4012 740 pts/5 S+ 14:38 0:00 egrep > \<11067\>|^USER\> > dstromberg-laptop-dstromberg:~/src/python-mem-use i686-pc-linux-gnu 10916 - > above cmd done 2011 Wed Mar 16 02:38 PM > > So on Python 2.6.6 + Ubuntu 10.10, the second is actually a little smaller > than the first. > > Some issues you might ponder: > 1) Does FreeBSD's malloc/free know how to free unused memory pages in the > middle of the heap (using mmap games), or does it only sbrk() down when the > end of the heap becomes unused, or does it never sbrk() back down at all? > I've heard various *ix's fall into one of these 3 groups in releasing unused > pages. > > 2) It mijght be just an issue of how frequently the interpreter garbage > collects; you could try adjusting this; check out the gc module. Note that > it's often faster not to collect at every conceivable opportunity, but this > tends to add up the bytes pretty quickly in some scripts - for a while, > until the next collection. So your memory use pattern will often end up > looking like a bit of a sawtooth function. > > 3) If you need strict memory use guarantees, you might be better off with a > language that's closer to the metal, like C - something that isn't garbage > collected is one parameter to consider. If you already have something in > CPython, then Cython might help; Cython allows you to use C datastructures > from a dialect of Python. > > > -- http://mail.python.org/mailman/listinfo/python-list
Numpy and Scipy for Python3.5
Can I find those modules in the FreeBSD ports? -- https://mail.python.org/mailman/listinfo/python-list
Python27.dll module error from Python 2.7.15/PCbuild/get_externals.bat
I am trying to compile the freshly downloaded Python 2.7.15. When the PCBuild/build.bat goes to pull-in the external modules along with their dependencies it encounters this error for each of the external modules. F:\Dev\depot\tools\source\python\Python-2.7.15>.\PCbuild\get_externals.bat Using "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\..\externals\pyth onx86\tools\python.exe" (found in externals directory) Fetching external libraries... e is e Fetching bzip2-1.0.6... Traceback (most recent call last): File "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\get_external.py" , line 7, in from urllib.request import urlretrieve File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\urllib\request.py", line 88, in import http.client File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\http\client.py", line 71, in import email.parser File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\email\parser.py", line 12, in from email.feedparser import FeedParser, BytesFeedParser File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\email\feedparser.py", line 27, in from email._policybase import compat32 File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\email\_policybase.py", line 9, in from email.utils import _has_surrogates File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\email\utils.py", line 29, in import socket File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\socket.py", line 49, in import _socket ImportError: Module use of python27.dll conflicts with this version of Python. Fetching bsddb-4.7.25.0... Traceback (most recent call last): File "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\get_external.py" I tried installing python versions 3.6.4 and 2.7.15 to see if it works because I read in the build script that if python is already installed then it will use that else it will install it's own python in externals and use it. But no luck! It keeps giving me the same error again and again. Even if I execute "builds.bat -e" it gets into the same trap though it goes ahead and compiles but then compiler throws error due to half-baked external modules. Any help will be highly appreciated ! --Amit Kumar Singh -- https://mail.python.org/mailman/listinfo/python-list
Regarding problem faced to run pandas
Dear Sir/Madam, After successful installation of PIP for PANDAS when I try to run any program, It gives error (Screenshot attached) The screenshot of the problem is attached herewith for your kind information . Kindly help me to resolve such problem. -- *Thanks & Regards * *Amit Kumar Jain* *Jaipur, Rajasthan* *India* -- *Thanks & Regards * *Amit Kumar Jain* *PGT(CS)* *KVS, (Under **Ministry of HRD)* -- https://mail.python.org/mailman/listinfo/python-list
Problem in importing pandas
Dear Sir/Madam, After *successful installation of PIP for PANDAS *when I try to *import pandas*, It gives error as given below - >>> import pandas as pd Traceback (most recent call last): File "", line 1, in import pandas as pd File "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\__init__.py", line 55, in from pandas.core.api import ( File "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\api.py", line 29, in from pandas.core.groupby import Grouper, NamedAgg File "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\groupby\__init__.py", line 1, in from pandas.core.groupby.generic import DataFrameGroupBy, NamedAgg, SeriesGroupBy File "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\groupby\generic.py", line 60, in from pandas.core.frame import DataFrame File "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\frame.py", line 124, in from pandas.core.series import Series File "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\series.py", line 4572, in Series._add_series_or_dataframe_operations() File "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\generic.py", line 10349, in _add_series_or_dataframe_operations from pandas.core.window import EWM, Expanding, Rolling, Window File "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\window\__init__.py", line 1, in from pandas.core.window.ewm import EWM # noqa:F401 File "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\window\ewm.py", line 5, in import pandas._libs.window.aggregations as window_aggregations ImportError: DLL load failed while importing aggregations: The specified module could not be found. I am not able to run pandas. *Kindly help me to resolve this problem.* *Regards * *Amit Kumar Jain* -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem in importing pandas
For the same problem, The solution, I found is to install package spicy. Then *import spicy* along with *import pandas. * It really works - But the instructions should be - *import spicy* *import pandas* On Fri, 24 Apr 2020, 01:12 MRAB, wrote: > On 2020-04-23 18:57, Amit Jain wrote: > > Dear Sir/Madam, > > After *successful installation of PIP for PANDAS *when I try to *import > > pandas*, It gives error as given below - > > > >>>> import pandas as pd > > Traceback (most recent call last): > >File "", line 1, in > > import pandas as pd > >File > > > "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\__init__.py", > > line 55, in > > from pandas.core.api import ( > >File > > > "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\api.py", > > line 29, in > > from pandas.core.groupby import Grouper, NamedAgg > >File > > > "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\groupby\__init__.py", > > line 1, in > > from pandas.core.groupby.generic import DataFrameGroupBy, NamedAgg, > > SeriesGroupBy > >File > > > "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\groupby\generic.py", > > line 60, in > > from pandas.core.frame import DataFrame > >File > > > "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\frame.py", > > line 124, in > > from pandas.core.series import Series > >File > > > "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\series.py", > > line 4572, in > > Series._add_series_or_dataframe_operations() > >File > > > "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\generic.py", > > line 10349, in _add_series_or_dataframe_operations > > from pandas.core.window import EWM, Expanding, Rolling, Window > >File > > > "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\window\__init__.py", > > line 1, in > > from pandas.core.window.ewm import EWM # noqa:F401 > >File > > > "C:\Users\Amit\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\window\ewm.py", > > line 5, in > > import pandas._libs.window.aggregations as window_aggregations > > ImportError: DLL load failed while importing aggregations: The specified > > module could not be found. > > > > > > I am not able to run pandas. > > *Kindly help me to resolve this problem.* > > > After searching on Google, this looks like your problem: > > ImportError: DLL load failed with Windows wheel for 1.0.2 and 1.0.3 #32857 > https://github.com/pandas-dev/pandas/issues/32857 > > The last comment (jshridha) gives a solution. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
OSDC::Israel Conference 26-28 Feb. 2006
== Open Source Developers' Conference, 26-28 February, 2006, Netanya, Israel == Announcement and Call for Papers http://www.osdc.org.il/call_for_paper.html About -- The Open Source Developers' Conferences (OSDCs) are grassroots symposia originating from Australia. The conference tries to bring together the users of various OS technologies such as Perl, Python, Ruby, Tcl, PHP, MySQL, PostgreSQL, Subversion and more. The Israeli OSDC is organized by the Israeli Perl Mongers and the Israeli Python user group. Our aim is to bring together practitioners, scholars, students, programmers, researchers and managers from different areas to discuss their views on various aspects of the Open Source technologies, to share knowledge and to have fun while doing so. Structure -- The conference will last for 3 days with 3 parallel tracks of presentations. Presentations will be given in either Hebrew or English, depending on the speaker's preference (the language will be listed in advance). Call for Papers Recommended Topics for Python Related Presentations: * Python based web & content-management technology (e.g. Zope) * Major or Interesting packages (e.g. Twisted) * Language development and new implementations (e.g. PyPy) * Interfacing other languages (e.g. boost-python) The examples given above are suitable for long presentations or tutorials, but we also accept 40 and 20 minutes presentations, and 5 minute lightning talks. Any other topics which are interesting and relevant to Open Source Developers are also welcome. For submitting proposals: http://www.osdc.org.il/proposal.html For updates and more details: http://www.osdc.org.il/index.html -- http://mail.python.org/mailman/listinfo/python-list
OSDC::Israel Conference 26-28 Feb. 2006
== Open Source Developers' Conference, 26-28 February, 2006, Netanya, Israel == Announcement and Call for Papers http://www.osdc.org.il/call_for_paper.html About -- The Open Source Developers' Conferences (OSDCs) are grassroots symposia originating from Australia. The conference tries to bring together the users of various OS technologies such as Perl, Python, Ruby, Tcl, PHP, MySQL, PostgreSQL, Subversion and more. The Israeli OSDC is organized by the Israeli Perl Mongers and the Israeli Python user group. Our aim is to bring together practitioners, scholars, students, programmers, researchers and managers from different areas to discuss their views on various aspects of the Open Source technologies, to share knowledge and to have fun while doing so. Structure -- The conference will last for 3 days with 3 parallel tracks of presentations. Presentations will be given in either Hebrew or English, depending on the speaker's preference (the language will be listed in advance). Call for Papers Recommended Topics for Python Related Presentations: * Python based web & content-management technology (e.g. Zope) * Major or Interesting packages (e.g. Twisted) * Language development and new implementations (e.g. PyPy) * Interfacing other languages (e.g. boost-python) The examples given above are suitable for long presentations or tutorials, but we also accept 40 and 20 minutes presentations, and 5 minute lightning talks. Any other topics which are interesting and relevant to Open Source Developers are also welcome. For submitting proposals: http://www.osdc.org.il/proposal.html For updates and more details: http://www.osdc.org.il/index.html -- http://mail.python.org/mailman/listinfo/python-list
matching a string to extract substrings for which some function returns true
Hello All, say you have some string: "['a', 'b', 1], foobar ['d', 4, ('a', 'e')]" Now i want to extract all substrings for which "isinstance(eval(substr), list)" is "True" . now one way is to walk through the whole sample string and check the condition, I was wondering if there is any smarter way of doing the same, may be using regular-expressions. Thanks, amit. Endless the world's turn, endless the sun's spinning Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: matching a string to extract substrings for which some function returns true
Well actually the problem is I have a list of tuples which i cast as string and then put in a html page as the value of a hidden variable. And when i get the string again, i want to cast it back as list of tuples: ex: input: "('foo', 1, 'foobar', (3, 0)), ('foo1', 2, 'foobar1', (3, 1)), ('foo2', 2, 'foobar2', (3, 2))" output: [('foo', 1, 'foobar', (3, 0)), ('foo1', 2, 'foobar1', (3, 1)), ('foo2', 2, 'foobar2', (3, 2))] I hope that explains it better... cheers, On 11/22/05, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Tue, 22 Nov 2005 16:57:41 +0530, Amit Khemka wrote: > > > Hello All, > > > > say you have some string: "['a', 'b', 1], foobar ['d', 4, ('a', 'e')]" > > Now i want to extract all substrings for which > > "isinstance(eval(substr), list)" is "True" . > > That's an awfully open-ended question. Is there some sort of structure to > the string? What defines a substring? What should you get if you extract > from this string? > > "[]" > > Is that one list or five? > > > > now one way is to walk through the whole sample string and check the > > condition, > > Yes. Where does the string come from? Can a hostile user pass bad strings > to you and crash your code? > > > -- > Steven. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Endless the world's turn, endless the sun's spinning Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: matching a string to extract substrings for which some functionreturns true
Fredrik, thanks for your suggestion. Though the html page that are generated are for internal uses and input is verified before processing. And more than just a solution in current context, actually I was a more curious about how can one do so in Python. cheers, amit. On 11/22/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Amit Khemka wrote: > > > Well actually the problem is I have a list of tuples which i cast as > > string and then put in a html page as the value of a hidden variable. > > And when i get the string again, i want to cast it back as list of tuples: > > ex: > > input: "('foo', 1, 'foobar', (3, 0)), ('foo1', 2, 'foobar1', (3, 1)), > > ('foo2', 2, 'foobar2', (3, 2))" > > output: [('foo', 1, 'foobar', (3, 0)), ('foo1', 2, 'foobar1', (3, 1)), > > ('foo2', 2, 'foobar2', (3, 2))] > > > > I hope that explains it better... > > what do you think happens if the user manipulates the field values > so they contain, say > > os.system('rm -rf /') > > or > > "'*'*100*2*2*2*2*2*2*2*2*2" > > or something similar? > > if you cannot cache session data on the server side, I'd > recommend inventing a custom record format, and doing your > own parsing. turning your data into e.g. > > "foo:1:foobar:3:0+foo1:2:foobar1:3:1+foo2:2:foobar2:3:2" > > is trivial, and the resulting string can be trivially parsed by a couple > of string splits and int() calls. > > to make things a little less obvious, and make it less likely that some > character in your data causes problems for the HTML parser, you can > use base64.encodestring on the result (this won't stop a hacker, of > course, so you cannot put sensitive data in this field). > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Endless the world's turn, endless the sun's spinning Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: matching a string to extract substrings for which somefunctionreturns true
thanks for you suggestions :-) .. cheers, On 11/23/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > I wrote: > > > if you cannot cache session data on the server side, I'd > > recommend inventing a custom record format, and doing your > > own parsing. turning your data into e.g. > > > >"foo:1:foobar:3:0+foo1:2:foobar1:3:1+foo2:2:foobar2:3:2" > > > > is trivial, and the resulting string can be trivially parsed by a couple > > of string splits and int() calls. > > on the other hand, the "myeval" function I posted here > > http://article.gmane.org/gmane.comp.python.general/433160 > > should be able to deal with your data, as well as handle data from > malevolent sources without bringing down your computer. > > just add > > if token[1] == "(": > out = [] > token = src.next() > while token[1] != ")": > out.append(_parse(src, token)) > token = src.next() > if token[1] == ",": > token = src.next() > return tuple(out) > > after the corresponding "[" part, and call it like: > > data = myeval("[" + input + "]") > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Endless the world's turn, endless the sun's spinning Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
How do i do this
For some commad Linux like (pdbedit) its not possible to supply password in the command line itself while we add a samba user account into the SAM database .. Now I want' to design an AddAccount() method in Python i.e when we can't do "pdbedit -adduser x%password" How do I manage to create an account usign the AddAccount() Python function ?? -- -Amit http://www.geocities.com/broamit -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQBC3HHp/u1Xr7tKTYARAv6eAJoDpKVv45v/M7NSH+xekpX6jasBJACeLcB/ lSIVQ0AMXFQrKPLZFOd6Qno= =Tltk -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
[newbie] - How to remain at prompt after script execution?
I am a total newbie learning the very basics I would like to excute a script and upon completion, how can I just a python prompt with the functions and variables already defined. I know you can do this in the window gui(IDLE). I was wondering if this can be done in POSIX systems as well. -- http://mail.python.org/mailman/listinfo/python-list
Re: [newbie] - How to remain at prompt after script execution?
Thanx Fredrik, that works and thats what I wanted. Amit "Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Amit Dhingra wrote: > > > I would like to excute a script and upon completion, how can I just a python > > prompt with the functions and variables already defined. > > > > I know you can do this in the window gui(IDLE). I was wondering if this can > > be done in POSIX systems as well. > > does "python -i" do what you want? > > $ python -h > usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ... > Options and arguments (and corresponding environment variables): > -c cmd : program passed in as string (terminates option list) > -d : debug output from parser (also PYTHONDEBUG=x) > -E : ignore environment variables (such as PYTHONPATH) > -h : print this help message and exit > -i : inspect interactively after running script, (also PYTHONINSPECT=x) > and force prompts, even if stdin does not appear to be a terminal > ... > > $ more myprogram.py > message = "hello, world" > print messae > $ python -i myprogram.py > hello, world > >>> print message.upper() > HELLO, WORLD > > > > > -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I get the variable to subtract the input please?
On Tue, Nov 19, 2013 at 9:56 AM, Ed Taylor wrote: > This will be very simple to most of you I guess but it's killing me! > > print ("Please type in your age") > age = input () > leave = 16 > print ("You have" + leave - age + "years left at school") > > I want to have an input where the users age is inserted and then subtracted > from the variable age which is set to 16 and the answer displayed as You have > x years left at school. I assume you are using Python 3. In that case, the input() function always returns a string: >>> age = input() 10 >>> age '10' >>> age - 10 Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for -: 'str' and 'int' And hence you cannot perform a subtraction operation. You will have to convert the input into a data type such as an integer or a float and then try to do any mathematical operation: >>> int(age) - 10 0 >>> float(age)-10 0.0 Hope that helps. Best, Amit. -- http://echorand.me -- https://mail.python.org/mailman/listinfo/python-list
Re: Using try-catch to handle multiple possible file types?
On Tue, Nov 19, 2013 at 5:13 PM, Victor Hooi wrote: > Hi, > > I have a script that needs to handle input files of different types > (uncompressed, gzipped etc.). > > My question is regarding how I should handle the different cases. > > My first thought was to use a try-catch block and attempt to open it using > the most common filetype, then if that failed, try the next most common type > etc. before finally erroring out. > > So basically, using exception handling for flow-control. > > However, is that considered bad practice, or un-Pythonic? > > What other alternative constructs could I also use, and pros and cons? > > (I was thinking I could also use python-magic which wraps libmagic, or I can > just rely on file extensions). > > Other thoughts? How about starting with a dictionary like this: file_opener = {'.gz': gz_opener, '.txt': text_opener, '.zip': zip_opener} # and so on. where the *_opener are say functions which does the job of actually opening the files. The above dictionary is keyed on file extensions, but perhaps you would be better off using MIME types instead. Assuming you go ahead with using MIME type, how about using python-magic to detect the type and then look in your dictionary above, if there is a corresponding file_opener object. If you get a KeyError, you can raise an exception saying that you cannot handle this file. How does that sound? Best, Amit. -- http://echorand.me -- https://mail.python.org/mailman/listinfo/python-list
Re: Python application for rpm creation
On Wed, Nov 27, 2013 at 1:39 AM, Unix SA wrote: > >> Sounds to me more like he is looking to package some other in house >> software, as opposed to packaging python specific libraries, etc.. > > - Yes, This is exactly i am looking at > > >> Doing an apt-cache search on my Ubuntu desktop results with a project, >> Spectacle, coincidentally written in Python. (I haven't really looked > into >> it): >> http://meego.gitorious.org/meego-developer-tools/spectacle > > this looks useful, i shall looking to this... or may be try myself writing > something. > > if you guys ( others ) got something else for Redhat Linux rpm creation do > let me know. I played with creating a RPM SPEC file "generator" for Sphinx documentation: https://github.com/amitsaha/sphinx_doc_packaging It's written in Python, so perhaps may help with you a starting point. Best, Amit. -- http://echorand.me -- https://mail.python.org/mailman/listinfo/python-list
Re: input() on python 2.7.5 vs 3.3.2
On Fri, Dec 13, 2013 at 12:45 AM, wrote: > Can someone explain? Thanks. > > Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit > (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> x = input() > Hello there >>>> print(x) > Hello there In Python 3, input() considers an input as a string and returns the input as a string. This is the behavior of raw_input() in Python 2. > > Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> x = input() > Hello there > Traceback (most recent call last): > File "", line 1, in > File "", line 1 > Hello there > ^ > SyntaxError: unexpected EOF while parsing In Python 2, input() expects valid Python as it's input. If you provide your input as 'Hello there' (a Python string), it won't complain. HTH, Amit. -- http://echorand.me -- https://mail.python.org/mailman/listinfo/python-list
Have you ever wondered why there are so many flavors of python. This post answers all your queries.
http://www.techdarting.com/2014/03/why-different-flavors-of-python.html -- https://mail.python.org/mailman/listinfo/python-list
Calling Python Script from an SQL Proceudre
Hi All, I am trying to search on the Internet if i can call a Python Script from an SQL Procedure. All the information found on Internet is about connecting to a database from Python through a Python script.But, i want the other way round. Any Help will be appreciated -- Thanks and Regards, Amit Goutham Ph:+91-8867801035 -- https://mail.python.org/mailman/listinfo/python-list
Re: Calling Python Script from an SQL Proceudre
Hi Laura, Thanks a Lot for the reply. I wanted to know if calling a Python script from SAP HANA database is possible. Thanks! On Jun 3, 2015 9:43 PM, "Laura Creighton" wrote: > In a message of Wed, 03 Jun 2015 15:17:16 +0530, Amit Goutham writes: > >Hi All, > >I am trying to search on the Internet if i can call a Python Script from > an > >SQL Procedure. > >All the information found on Internet is about connecting to a database > >from Python through a Python script.But, i want the other way round. > > > >Any Help will be appreciated > > > >-- > >Thanks and Regards, > >Amit Goutham > >Ph:+91-8867801035 > > You certainly can with postgreql, see > http://www.postgresql.org/docs/current/static/plpython.html > > I don't know about other SQL servers. > > Laura > -- https://mail.python.org/mailman/listinfo/python-list
argparse: use of double dash to separate options and positional arguments
Hello, I'm trying to use argparse in a program that gets some options and positional arguments. I want to collect all the positional arguments in a single argument using the REMAINDER option to add_argument() as shown bellow: parser = argparse.ArgumentParser(description='Test argparse') parser.add_argument('-v', '--verbose', action='store_true') parser.add_argument('cmd_args', nargs=argparse.REMAINDER) print parser.parse_args() This works well unless the first positional argument starts with a '-'. For example, with the above code my_prog -v hello world works well, but my_prog -v -x hello world Fails with an error message 'error: unrecognized arguments: -x'. If I invoke the program with a '--' at the end of the options (as I understand is a common standard and a POSIX recommendation), as in: my_prog -v -- -x hello world It works well again. However, a few questions remain: Firstly, as far as I can tell the use of '--' is not documented in the argparse documentation (but the code of argparse clearly shows that it is a feature). Secondly, when using '--', this string itself is inserted into the list of the collected positional arguments (in the above example in the cmd_args variable): $ ./my_prog -v -- -x hello world Namespace(cmd_args=['--', '-x', 'hello', 'world'], verbose=True) It's quiet easy to check for it and remove it if it exists, but it still seems like it shouldn't be there - it is not really an argument, just a delimiter. Am I doing anything wrong, or is this a bug? I hope someone here can shed some light on this. Thanks, Amit -- -- https://mail.python.org/mailman/listinfo/python-list
Re: argparse: use of double dash to separate options and positional arguments
Peter Otten <__pete...@web.de> [2015-11-06 11:57 +0100]: For example, with the above code my_prog -v hello world works well, but my_prog -v -x hello world Fails with an error message 'error: unrecognized arguments: -x'. This looks like a bug to me. Please report it on bug.python.org. Why does it looks like a bug? To me it seems okay - argparse expects that an argument that starts with '-' is an option, and it also expects to be told about all possible options, so it complains on encountering an unrecognized 'option'. This is why a special delimiter is needed to mark the 'end of options'. If I invoke the program with a '--' at the end of the options (as I understand is a common standard and a POSIX recommendation), as in: my_prog -v -- -x hello world It works well again. However, a few questions remain: Firstly, as far as I can tell the use of '--' is not documented in the argparse documentation (but the code of argparse clearly shows that it is a feature). Secondly, when using '--', this string itself is inserted into the list of the collected positional arguments (in the above example in the cmd_args variable): $ ./my_prog -v -- -x hello world Namespace(cmd_args=['--', '-x', 'hello', 'world'], verbose=True) It's quiet easy to check for it and remove it if it exists, but it still seems like it shouldn't be there - it is not really an argument, just a delimiter. I'm not sure about this one; one purpose of REMAINDER is to pass on the unprocessed arguments to another program/script, and this might follow the same convention. Should parser.add_argument('-v', '--verbose', action='store_true') parser.add_argument('cmd_args', nargs=argparse.REMAINDER) args = parser.parse_args() subprocess.call(["rm"] + args.cmd_args) $ my_prog -v -- -r foo attempt to delete two files "-r" and "foo" or remove the "foo" directory? The first is the safer alternative, and as you say stripping the "--" is easy. I'm using the REMAINDER exactly for passing on arguments to another program, as in your example. I would expect that everything after the '--' should be passed on as is - it should be up to the other program to decide what to do with the arguments it receives (So in your examples, rm would actually try to remove the "foo" directory). And although stripping the '--' is easy, why should the user of argparse need to handle it? Still unclear to me. Cheers, Amit -- https://mail.python.org/mailman/listinfo/python-list
Default Admin user on weblogic domain deleted after executing create command using WLST
Hello All, we observed that user exactly deleted when 'create' cmd is executed: filestore = create("wlstProperties.getProperty(fileStoreName)", "FileStore") jmsServer = create("AUAJMSServer", "JMSServer") ... .. etc. http://groups.google.com/group/comp.lang.java.programmer/browse_thread/thread/1927322accdb6e6e/223e1c7cd208a86c Please suggestion... regards, Amit J. -- http://mail.python.org/mailman/listinfo/python-list
writing IM bots
Hello, I am trying to write an IM Bot, which automatically replies to a message, in Python. I was wondering If there are python modules for connecting to Yahoo!, msn networks ... ideally I would like to have a multithreaded module. This is one I found for msn, if anyone has used it please comment, - http://users.auriga.wearlab.de/~alb/msnlib/ cheers, amit. -- Endless the world's turn, endless the sun's spinning Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: writing IM bots
thank you all for ur suggestions .. I got msnp and curfoo(for yahoo) customized and working :-) .. though they are pretty slow in responding to messages ... will try jabber based protocols, cheers, amit. On 12/14/05, Linsong <[EMAIL PROTECTED]> wrote: >Why not twisted.words, for me, twisted can solved almost all(if not > all, you can implement it under twisted framework easily) internet > protocol related tasks and it is really *cool*! >Twisted Words includes: > > * Low-level protocol implementations of OSCAR (AIM and ICQ), IRC, > MSN, TOC (AIM). > * Jabber libraries. > * Prototypes of chat server and client frameworks built on top of > the protocols. > >I have used twisted.words for IRC and MSN, it works very well. Never > forget to investigate the other projects of twisted, it will give you a > lot back. > http://twistedmatrix.com/projects/words/ > > Good Luck! > Linsong > > > Amit Khemka wrote: > > >Hello, > >I am trying to write an IM Bot, which automatically replies to a > >message, in Python. > >I was wondering If there are python modules for connecting to Yahoo!, > >msn networks ... > >ideally I would like to have a multithreaded module. > > > >This is one I found for msn, if anyone has used it please comment, > >- http://users.auriga.wearlab.de/~alb/msnlib/ > > > >cheers, > >amit. > > > > > >-- > > > >Endless the world's turn, endless the sun's spinning > >Endless the quest; > >I turn again, back to my own beginning, > >And here, find rest. > > > > > > -- Endless the world's turn, endless the sun's spinning Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Timeout at command prompt
One way would be to use 'signal' s ... something like this should work import signal TIMEOUT = 5 # number of seconds your want for timeout signal.signal(signal.SIGALRM, input) signal.alarm(TIMEOUT) def input(): try: foo = raw_input() return foo except: # timeout return cheers, amit. On 11 Jan 2006 13:24:34 -0800, Thierry Lam <[EMAIL PROTECTED]> wrote: > I can use the python function raw_input() to read any input from the > user but how can I add a timeout so that my program exits after x > period of time when no input has been entered. > > Thierry > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Endless the world's turn, endless the sun's spinning Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I create a dict that sets a flag if it's been modified
Ideally, I would have made a wrapper to add/delete/modify/read from the dictionay. But other than this, one way i can think straight off is to "pickle" the dict, and to see if the picked object is same as current object. cheers, amit. On 12 Jan 2006 01:15:38 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I can think of several messy ways of making a dict that sets a flag if > it's been altered, but I have a hunch that experienced python > programmers would probably have an easier (well maybe more Pythonic) > way of doing this. > > It's important that I can read the contents of the dict without > flagging it as modified, but I want it to set the flag the moment I add > a new element or alter an existing one (the values in the dict are > mutable), this is what makes it difficult. Because the values are > mutable I don't think you can tell the difference between a read and a > write without making some sort of wrapper around them. > > Still, I'd love to hear how you guys would do it. > > Thanks, > -Sandra > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Endless the world's turn, endless the sun's spinning Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Timeout at command prompt
its "Python 2.4.1" .. on linux On 12 Jan 2006 06:34:08 -0800, Thierry Lam <[EMAIL PROTECTED]> wrote: > Is there a windows equivalent for that solution? > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Endless the world's turn, endless the sun's spinning Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Timeout at command prompt
I tried it on "Python 2.4.1" on '2.6.11-1.1369_FC4smp with gcc version 4.0.0' .. which works fine .. may be it could be an issue with some other combinations .. cheers, amit On 12 Jan 2006 07:35:57 -0800, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Amit Khemka <[EMAIL PROTECTED]> writes: > > import signal > > TIMEOUT = 5 # number of seconds your want for timeout > > signal.signal(signal.SIGALRM, input) > > signal.alarm(TIMEOUT) > > > > def input(): > > try: > >foo = raw_input() > >return foo > > except: > > # timeout > > return > > This doesn't work with raw_input under linux, maybe because the > readline lib is snagging the timer interrupt or something. Use > sys.stdin.readline instead. SF bug: > > http://sourceforge.net/tracker/index.php?func=detail&aid=685846&group_id=5470&atid=105470 > -- > http://mail.python.org/mailman/listinfo/python-list > -- Endless the world's turn, endless the sun's spinning Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Timeout at command prompt
Another thing that can be tried is: import threading a="" def input(): global a a = raw_input() T = threading.Thread(target=input) T.start() T.join(2) ## does the trick ... I have not tested it but i guess should work. cheers, amit. On 1/12/06, Amit Khemka <[EMAIL PROTECTED]> wrote: > I tried it on "Python 2.4.1" on '2.6.11-1.1369_FC4smp with gcc version > 4.0.0' .. which works fine .. may be it could be an issue with some > other combinations .. > > cheers, > amit > > On 12 Jan 2006 07:35:57 -0800, Paul Rubin > <"http://phr.cx"@nospam.invalid> wrote: > > Amit Khemka <[EMAIL PROTECTED]> writes: > > > import signal > > > TIMEOUT = 5 # number of seconds your want for timeout > > > signal.signal(signal.SIGALRM, input) > > > signal.alarm(TIMEOUT) > > > > > > def input(): > > > try: > > >foo = raw_input() > > >return foo > > > except: > > > # timeout > > > return > > > > This doesn't work with raw_input under linux, maybe because the > > readline lib is snagging the timer interrupt or something. Use > > sys.stdin.readline instead. SF bug: > > > > http://sourceforge.net/tracker/index.php?func=detail&aid=685846&group_id=5470&atid=105470 > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > > Endless the world's turn, endless the sun's spinning > Endless the quest; > I turn again, back to my own beginning, > And here, find rest. > -- Endless the world's turn, endless the sun's spinning Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encode filenames to safe format
On 7/20/06, Dara Durum <[EMAIL PROTECTED]> wrote: > Hi ! > > I want to encode filenames to safe format, like in browser url (space -> > %20, etc.). > What the module and function name that helps me in this project ? > import urllib urllib.quote('file name') cheers, amit -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: import a user created python file as module
On 30 Jul 2006 23:07:07 -0700, Phoe6 <[EMAIL PROTECTED]> wrote: > Hi, > I have the following directory structure in my project. > Base: > file1.py > file2.py > Directory1: >file1-dir1.py > > I am able to import file1 into file2.py > What I need to do is, import file1 in the file file1-dir1.py. > I did not create the entire dir structure as package. Adding > __init__.py file in both Base: as well as Directory1: is not helpful. I > am unable to import file1 in the file1-dir1.py. It is not able to find > the path of the file1.py. > > How and what should I do to import file1.py into file1-dir1.py ? Please > give me some references to the tutorial topic which I can study as > well. Modify the path where python searches for modules, for example in file1-dir1.py add: import sys sys.path.append("/path/to/Base") import file1 cheers, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to safely extract dict values
On 7/31/06, David Zaret <[EMAIL PROTECTED]> wrote: > i have a dict with a particular key - the values for this key will be > None, one valid scalar, or a list: > > {mykey, None} > {mykey, "foo"} > {mykey, ["bar", "baz"]} > > let's ignore the None case - in the case of the one or many values, i > want to suck the values into a list. here's one way to do this: > > if mydict.has_key(mykey): > vals=[] > _v = mydict[mykey] > if isinstance(_v, types.ListType): > vals.extend(_v) > else: > vals.append(_v) > # now we can safely iterate through acts > for val in vals: > . how about: vals = [] for val in mydict.values(): try: vals.extend(val) except: vals.append(val) cheers, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to safely extract dict values
oops ! my mistake :-D On 7/31/06, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Amit Khemka wrote: > > how about: > > > > vals = [] > > for val in mydict.values(): > > try: vals.extend(val) > > except: vals.append(val) > > >>> l = [] > >>> l.extend((1, 2)) > >>> l > [1, 2] > >>> l.extend('ab') > >>> l > [1, 2, 'a', 'b'] Oops, my mistake ... jumped in too quickly ! cheers, -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL issues
On 8/1/06, David Bear <[EMAIL PROTECTED]> wrote: > I am trying to use PIL and when building it, PIL fails to find my jpeg > library. I am using a python 2.4.3 that I build myself on Suse linux 9.3. I > do have the following jpeg libraries: > > rpm -qa | grep jpeg > jpeg-6b-738 > libjpeg-32bit-9.3-7 > libjpeg-6.2.0-738 > > > yet, when building PIL I get: > > python setup.py build_ext -i > running build_ext > > PIL 1.1.5 BUILD SUMMARY > > version 1.1.5 > platform linux2 2.4.2 (#4, Jul 27 2006, 14:34:30) > [GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] > > *** TKINTER support not available > *** JPEG support not available > --- ZLIB (PNG/ZIP) support ok > *** FREETYPE2 support not available > > To add a missing option, make sure you have the required > library, and set the corresponding ROOT variable in the > setup.py script. > > I don't know what ROOT variable the message is referring too. Any advice > would be appreciated. This is because PIL, is not able to find the jpeg/other libraries . 1. Install jpeg-libs from sources: (http://www.ijg.org/files/jpegsrc.v6b.tar.gz) 2.0: "clean" the PIL build 2.1 In setup.py that comes with PIL, set the JPEG_ROOT to the jpeg-lib path 3.0 run setup.py I hope that should help .. cheers, amit -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: using globals
On 8/3/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi, > > I have got a problem with importing global variables. For instance I have > got two files: > > # t1.py #t2.py > > counter = 1 > > def counter_adder(filenr): def show_adder(): >global counter import t1 >counter+= 1 print("adder > is %d" % t1.counter) >if filenr == 1: > show_adder() >else: > import t2 > t2.show_adder() > > def show_adder(): >print("adder is %d" % counter) > > >>counter_adder(1) > adder is 2 > >>counter_adder(2) > adder is 1 > > When I look at the outcome of two function calls I expected no differences > but much to my surprise it goes wrong when the global variable is imported. > It doesn't give the updated value but the value it get when instantiated. > Who come? What should I do to get the updated value call: counter_adder(2) In "t2.py", you are importing a python module "t1.py". And its very logical that all the (global) variables in "t1.py" have the value which one would expect after execution of the "t1.py" otherwise. And hence you see value of counter as 1. (or in other words you are accessing two different instances of variable "counter") I would rather advice that you pass counter as a variable to the function-calls, or use a class. cheers, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Running queries on large data structure
On 8/3/06, Christoph Haas <[EMAIL PROTECTED]> wrote: > On Wednesday 02 August 2006 22:24, Christoph Haas wrote: > > I have written an application in Perl some time ago (I was young and > > needed the money) that parses multiple large text files containing > > nested data structures and allows the user to run quick queries on the > > data. [...] > > I suppose my former posting was too long and concrete. So allow me to try > it in a different way. :) > > The situation is that I have input data that take ~1 minute to parse while > the users need to run queries on that within seconds. I can think of two > ways: > > (1) Database > (very quick, but the input data is deeply nested and it would be > ugly to convert it into some relational shape for the database) > (2) cPickle > (Read the data every now and then, parse it, write the nested Python > data structure into a pickled file. The let the other application > that does the queries unpickle the variable and use it time and > again.) Though some sugggested maintaining data in some XML structures, I was wondering that if you considered using some native XML database like BDB XML. 1. It allows you to retain hierarchical structure of data. 2. It also has support for precompiled queries. 3. You can open a persistent connection. cheers, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to change the path for python binary?
On 8/10/06, Nico Grubert <[EMAIL PROTECTED]> wrote: > Hi there, > > I have installed Python 2.3.5 on Suse Linux 10. > If I enter "python" in the shell, the Python 2.3.5 interpreter is called. > > After I installed Python 2.4.3. the Python 2.4.3 interpreter is called > which is the default behaviour I guess. > > "which python" brings me "/usr/local/bin/python" which calls the Python > 2.4.3 interpreter. > > My question now is: > What do I have to do in order to get the Python 2.3.5 interpreter each > time I enter "python" in the shell? There could be various ways of doing so, like: Option 1: open your shell preference file ( ex. for bash ~/.bashrc) and add an alias: alias python="/path/to/python/version/of/your/choise" Option 2: make /usr/local/bin/python a symlink to python2.3.5 cheers, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with async xmlrpc design
On 8/17/06, David Hirschfield <[EMAIL PROTECTED]> wrote: > I have an xmlrpc client/server system that works fine, but I want to > improve performance on the client side. > > Right now the system operates like this: > > client makes request from server (by calling server.request() via xml-rpc) > server places "request" on queue and returns a unique ID to the calling > client > client repeatedly asks server if the request with the given ID is > complete via server.isComplete() > server eventually completes processing request > client eventually gets an affirmative from server.isComplete() and then > client pulls results from server via server.fetchResults() > > originally the client only made one request at a time, and each one was > processed and results fetched in order. > > I want to change this so that the client can send multiple requests to > the server and have them processed in the background. > There are a lot of different approaches to that process, and I'd like > advice on the best way to go about it. > > I could simply place the request checking and results fetching into a > thread or thread-pool so that the client can submit requests to some > kind of queue and the thread will handle submitting the requests from > that queue, checking for completion and fetching results. > > Unfortunately, that would mean lots of calls to the server asking if > each of the requests is complete yet (if I submit 100 requests, I'll be > repeatedly making 100 "are you done yet?" calls). I want to avoid that, > so I thought there would be some way to submit the request and then hold > open the connection to the server and wait on the completion, but still > allow the server to do work. > > Any advice on how to avoid polling the server over and over for request > completion, but also allowing the client to submit multiple requests > without waiting for each one to finish before submitting the next? One obvious improvement over your current scheme would be that instead of polling server for each request submitted, have a unified polling mechanism wherein server returns a list of "ids" of all processed request. But as you too mentioned polling is "often" not the best way, You may try say: 1. Upon submitting a request, client-server agree upon a port on which client will listen for the results. 2. Registering a callback function. (Googling would point to more elaborate discussions on pros and cons ) cheers, amit. Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: find, replace and save string in ascii file
On 23 Aug 2006 05:48:37 -0700, peter <[EMAIL PROTECTED]> wrote: > Hello all, > > I'm looking for an advice. > > Example (one block in ascii file): > $ > NAME='ALFA' > CODE='x' > $ > > There are many similar blocks in the file with different NAMEs and > different CODEs. What I'm looking for is a script that searchs through > whole file and finds all strings with name ALFA and based on what CODE > is after each ALFA (can be x, y or z) the ALFA name is replaced by > BETAx,BETAy or BETAz and so changed file saves. > > What I did is that I can find all strings which I need, next I change > these strings based on CODE, but what I can't is to replace old string > with new one, on the same position in the file. It always writes new > string at the end of the file. Here is my code A simpler way can be: 1. Read a 'block' from the input file, ( you can simply read a line starting with 'NAME' and keep on reading till you find a line with starting 'CODE') 2. Once you have read a 'block', make whatever you want changes to the NAME and then write the 'block' to a temperory file. If you want the output to be written to same file just 'move' this temperory file to the input file once you are done. Note: if there is other stuff in the input file, apart from such 'blocks' that you want to preserve, a small modification in step 1 would take care of it. hth, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging to a file and closing it again properly (logging module)
On 6/13/06, Christoph Haas <[EMAIL PROTECTED]> wrote: > Evening, > > I have an application that is running in an endless loop processing an > incoming queue. Every run is supposed to write a log file about the run > and then close it again. While the 'logging' module is generally working > well (even though the documentation makes me miss some proper examples > how everything works together) I can't seem to close the log file again > to open a new one. > > This is basically what I'm doing: > > log = logging.getLogger("myapplication") > log.addHandler(logging.FileHandler("/tmp/testfile")) > log.setLevel(logging.INFO) > log.info("foo") > > Now I'm missing a way to tell this handler to go away. Through 'ipython' > I found out there is a log.handlers array that contains all the > handlers. Perhaps I could delete all of them but I'm sure there is a > more proper way to close files again. > > Googling found me: > > .>>> logging._handlers.clear() > .>>> logging.root.handlers = [] > .>>> for l in logging.Logger.manager.loggerDict.values(): > .>>> l.handlers = [] You can "close" the logger by just removing the handler from the logging object # first creater a logger and file handler fooLogger = logging.getLogger('FOO') fooLogger.setLevel(logging.INFO) fl = logging.FileHandler('foo.txt) fl.setLevel(logging.INFO) fooLogger.addHandler(fl) # remove the handler once you are done fooLogger.removeHandler(fl) cheers, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Import: Multiple modules with same name
Hello All, I have multiple modules with same name in different directories (well I guess thats may not be a good practise, but i needed it for debugging and working with various versions). Now how do I import a module with specifying a path. Few minutes of googling suggested: import ihooks import os def my_import(filename): loader = ihooks.BasicModuleLoader() path, file = os.path.split(filename) name, ext = os.path.splitext(file) module = loader.find_module_in_dir(name, path) if not module: raise ImportError, name module = loader.load_module(name, module) return module But It looked like an overkill, Is there a more elegant and better way of doing it ? Thanks in advance, cheers, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: starting and stopping a program from inside a python script
You can store the pid of the process when started and later use it to kill it. cheers, On 3 Jul 2006 15:28:19 -0700, dfaber <[EMAIL PROTECTED]> wrote: > Aloha! > I want to terminate a process/program from within a python script. > > For example, > if I have a program say foo.sh that starts running, then I can run it > from within a python script using > os.popen('foo.sh') which starts a program/process say 'bar' > > At some point later, I want to kill 'bar'. Currently, I start off the > process and then when the python script exits, the process 'bar' is > still running and I have to issue ps -ef | grep 'bar' and then kill > it. > > Is there any better way of doing this? > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Generating multiple lists from one list
> On 7/6/06, Girish Sahani <[EMAIL PROTECTED]> wrote: > Thus, for the above list, my output should be: > [['a.1','b.3','c.2'],['a.1','b.4','c.2']] > Another example: Let l = ['a.1','b.3','b.4','c.2','c.6','d.3']. Then > output should be [['a.1','b.3','c.2','d.3'],['a.1','b.3','c.6','d.3'], > ['a.1','b.4','c.2','d.3'],[['a.1','b.4','c.6','d.3'] > > Can anyone suggest me a time-efficient method for doing this?? - x = ['a.1','b.3','b.4','c.2','c.6','d.3'] d = {} for y in x: l = d.get(y.split('.')[0], []) l.append(y) d[y.split('.')[0]] = l output = [[]] for l in d.values(): dfdf = output[:] ## ugly hack to work around references + for i in range(len(l)-1): for j in dfdf: k = j[:] output.append(k) # hack - for i in range(0, len(l)): for l1 in output[i*len(output)/len(l):((i+1)*len(output)/len(l))]: l1.append(l[i]) print output hope that helps ! cheers, amit. > hello ppl, > > Consider a list like ['a.1','b.3','b.4','c.2']. Here 'a','b','c' are > objects and 1,3,4,2 are their instance ids and they are unique e.g. a.1 > and b.1 cannot exist together. From this list i want to generate > multiple lists such that each list must have one and only one instance of > every object. > Thus, for the above list, my output should be: > [['a.1','b.3','c.2'],['a.1','b.4','c.2']] > Another example: Let l = ['a.1','b.3','b.4','c.2','c.6','d.3']. Then > output should be [['a.1','b.3','c.2','d.3'],['a.1','b.3','c.6','d.3'], > ['a.1','b.4','c.2','d.3'],[['a.1','b.4','c.6','d.3'] > > Can anyone suggest me a time-efficient method for doing this?? > > TIA, > girish > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: ElementTree : parse string input
> On 6 Jul 2006 07:38:10 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Any pointers to getting ElementTree to parse from a string would be > appreciated (of course I could dump it to a temp file, but that doesn't > seem elegent) You can use the "fromstring" method. Btw, did you looked at cElementTree module ? It claims to be much 'faster' and has very similar api as ElementTree Module. link: http://effbot.org/zone/celementtree.htm cheers, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Activate a daemon several times a day
did you considered using signals ?! I guess that could well serve the purpose .. more of signals: http://docs.python.org/lib/module-signal.html cheers, amit. On 7/6/06, Yves Glodt <[EMAIL PROTECTED]> wrote: > Hi, > > I have a daemon which runs permanently, and I want it to do a special > operation at some specifiy times every day, consider this configfile > extract: > > [general] > runat=10:00,12:00 > > > What would be the easiest and most pythonic way to do this? > Something like this pseudocode: > > while True: > if now(hours) in runat: > act() > sleep(60) > sleep(10) > > > Please enlighten me! > > Best regards, > Yves > -- > http://mail.python.org/mailman/listinfo/python-list > -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: all ip addresses of machines in the local network
On 23 Aug 2006 21:46:21 -0700, damacy <[EMAIL PROTECTED]> wrote: > hi, sandra. > > no, it's not as complicated as that. all i want to do is to load a > database onto different machines residing in the same network. i hope > there is a way doing it. or perhaps i have a poor understanding of how > networks work. > I expect that you would know the IP range for your network. Then you can simply 'ping' each IP in the range to find wether its alive. Moreover by your description I guess you would actually want to find all machines in your network that run a particular network service, to allow you to "distribute the database". In such case you can use "nmap" with -p option, to find all the machines which are listening on the particular port. hth, amit. Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: all ip addresses of machines in the local network
On 8/24/06, Amit Khemka <[EMAIL PROTECTED]> wrote: > On 23 Aug 2006 21:46:21 -0700, damacy <[EMAIL PROTECTED]> wrote: > > hi, sandra. > > > > no, it's not as complicated as that. all i want to do is to load a > > database onto different machines residing in the same network. i hope > > there is a way doing it. or perhaps i have a poor understanding of how > > networks work. > > > > I expect that you would know the IP range for your network. Then you > can simply 'ping' each IP in the range to find wether its alive. > Moreover by your description I guess you would actually want to find > all machines in your network that run a particular network service, to > allow you to "distribute the database". In such case you can use > "nmap" with -p option, to find all the machines which are listening on > the particular port. > > hth, > amit. It seems that I am not too busy, so here is a code which may work with a few tweaks here and there: _ import os # base and range of the ip addresses baseIP = "10.0.0." r = 6 interestingPort = 22 # port that you want to scan myIPs = [] for i in range(r): ip = baseIP+str(i) # It may need some customization for your case print "scanning: %s" %(ip) for output in os.popen("nmap %s -p %s" %(ip, interestingPort)).readlines(): if output.__contains__('%s/tcp open' %interestingPort): # i guess it would be tcp myIPs.append(ip) __ print myIPs hth, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: how can i change the text delimiter
sonald <[EMAIL PROTECTED]> wrote: > Hi, > Can anybody tell me how to change the text delimiter in FastCSV Parser > ? > By default the text delimiter is double quotes(") > I want to change it to anything else... say a pipe (|).. > can anyone please tell me how do i go about it? You can use the parser constructor to specify the field seperator: Python >>> parser(ms_double_quote = 1, field_sep = ',', auto_clear = 1) cheers, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: how can i change the text delimiter
On 8/30/06, Amit Khemka <[EMAIL PROTECTED]> wrote: > sonald <[EMAIL PROTECTED]> wrote: > > Hi, > > Can anybody tell me how to change the text delimiter in FastCSV Parser > > ? > > By default the text delimiter is double quotes(") > > I want to change it to anything else... say a pipe (|).. Btw, I forgot to mention that AFAIK, in CSV '"' (double quotes) are *not* field seperator delimiters character ! ',' (comma) is the default field seperator, and my earlier suggestion was considering that you want to change the default value for the field seperator. http://en.wikipedia.org/wiki/Comma-separated_values cheers, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: all ip addresses of machines in the local network
> in my program so far, multiple threads (255 threads in total) spawned > at once with each one of them trying to call socket.gethostbyaddr(ip) > function. i.e. if exception thrown, no machine found. i used .join() to > wait for the threads to terminate. it's fully working however the > problem is that it's too slow. it takes approx. 14 seconds to process > (i tried using 'ping' but it's even slower.). > > my question is.. is there a way to improve performance of the program > if i know what the port number would be? in my case, the port number > will always be constant although i have no clue on what ip addresses > would be (that's the reason all of 255 different addresses must be > tested). > > i tried the same function with the port number specified, > gethostbyaddr(ip:portno), but it is even 10-second slower than using > the same function without a port number specified (i.e. approx. 25 > seconds to complete). You can save some (DNS) overheads by escaping the call "gethostbyaddr", assuming you are not interested in knowing the 'Names' of the machines in your Network. And directly attempt to find the machines which are listenting on the specified port. A simple way of doing this would be to use socket.connect((ip, port)), if the connections succeds you have your machine ! ( There are various other ways of scanning ports, have a look at: http://insecure.org/nmap/nmap_doc.html#connect ) Though I am not sure how 'fast' it would be. Also remember that the time in scanning is affected by network-type, response-time-of-remote-machine, number-of-machines scanned etc. I would still be interested, in seeing how nmap(with some smart options) compares with the python code. ( In my network "nmap -osscan_limit -p 22 -T5 Class_D_Network" completes in 1.5 seconds !) cheers, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: how can i change the text delimiter
On 31 Aug 2006 00:25:38 -0700, sonald <[EMAIL PROTECTED]> wrote: > Hi, > I am using > Python version python-2.4.1 and along with this there are other > installables > like: > 1. fastcsv-1.0.1.win32-py2.4.exe > 2. psyco-1.4.win32-py2.4.exe > 3. scite-1.63-setup.exe > > We are freshers here, joined new... and are now into handling this > module which validates the data files, which are provided in some > predefined format from the third party. > The data files are provided in the comma separated format. > > The fastcsv package is imported in the code... > import fastcsv > and > csv = fastcsv.parser(strict = 1,field_sep = ',') > > can u plz tell me where to find the parser function definition, (used > above) > so that if possible i can provide a parameter for > text qualifier or text separator or text delimiter.. > just as {field_sep = ','} (as given above) > > I want to handle string containing double quotes (") > but the problem is that the default text qualifier is double quote > > Now if I can change the default text qualifier... to say pipe (|) > the double quote inside the string may be ignored... > plz refer to the example given in my previous query... > > Thanks.. As Fredrik and Skip mentioned earlier, The csv(from www.object-craft.com.au/projects/csv/) module you are using is obsolete. And an improved version is a part of standard python distribution. You should the standard module, in the way as suggested. You may like to do the following. 1. Convert all your data-file with say '|' as the quotechar (text delimiter) 2. Use (Import) the *standard* python cvs module () A sample code would look like: import csv # standard csv module distributed with python inputFile = "csv_file_with_pipe_as_quotchar.txt" reader = csv.reader(open(inputFile), quotechar='|') for row in reader: # do what ever you would like to do cheers, amit. Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: convert from date string to epoch
On 12/16/06, Stefan Antonelli <[EMAIL PROTECTED]> wrote: > Hi, > > i have to convert several timestamps. The given format, eg "-mm-dd > hh:mm:ss" > has to be converted to an epoch string. Is there any proper way to do this? > > If not, i have to split the given string and resolve this by a calculation? > > Thanks for help. > > Stefan. Check out timegm function in calendar module. The following function converts "mm/dd/" formats into epoch value, you can hack it for your date formats. def convertToEpoch(date): tup = map(int,date.split('/')) l = (tup[2], tup[0], tup[1], 0, 0, 0) epochs = calendar.timegm(l) return (int(epochs)) HTH, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: catching exceptions
On 16 Dec 2006 03:54:52 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi, In the following program, I have a class Test which has a property > x. Its setx function gets a string value and converts it into a float > and stores into it. > > class Test(object): > def _getx(self): > return self._x > def _setx(self,strvalue): > try: > self._x = float(strvalue) > except ValueError: > print 'Warning : could not set x attribute to %s' % > strvalue > x = property(_getx,_setx) > > > def func1(value): > a = Test() > try: > a.x = value > except ValueError: > #Pop up a error window. > print 'This is second catch' > > > func1('12') > func1('12e1') > func1('a') > > > > func1('12') > func1('12e1') > func1('a') > >>> func1('a') > Warning : could not set x attribute to a > > I am looking for a way to call func1's exception handler also. > Basically I want to have the class's error handler as the basic text > based one, and in the calling side, If I have gui, I will pop-up a > window and say the error message. > One solution is to remove the exception handling inside the class and > leave the entire thing to the caller (software people call this > client?) side -- if the caller has access to gui it will use gui or > else will print the message. Any other way? If I gather correctly, i guess in case of errors/exceptions in a class function, you want to get the error string. One thing that comes straight to my mind is, in such a case use a return statement in functions with two arguments. for example: def foo(self, value): try: a.x = value return True, '' except ValueError: return False, 'Float conversion error: %s' %(value) and when ever u call the function, check the first return value, It is false then alert/print the error message. HTH, amit. -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: trouble getting google through urllib
On 19 Dec 2006 16:12:59 -0800, Dr. Locke Z2A <[EMAIL PROTECTED]> wrote: > I looked at those APIs and it would appear that SOAP isn't around > anymore and there are no APIs for google translate :( Can anyone tell > me how to set the user-agent string in the HTTP header? import urllib2 req = urllib2.Request('http://www.google.com') # add 'some' user agent header req.add_header('User-Agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050524 Fedora/1.5 Firefox/1.5') up = urllib2.urlopen(req) cheers, amit -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to get PIL to load jpeg images
This is because PIL, is not able to find the jpeg library . 1. Install jpeg-libs from sources: (http://www.ijg.org/files/jpegsrc.v6b.tar.gz) 2.0: "clean" the PIL build 2.1 In setup.py that comes with PIL, set the JPEG_ROOT to the jpeg-lib path 3.0 run setup.py I hope that should help .. cheers, amit On 2/9/06, Andrew Gwozdziewycz <[EMAIL PROTECTED]> wrote: > On 2/7/06, Steve Holden <[EMAIL PROTECTED]> wrote: > > [EMAIL PROTECTED] wrote: > > > Someone out there must surely know - please! > > > > > > Peter > > > > > Try building the PIL from scratch. It might give you some insight as > to which library it exactly is looking for. I can remember when > compiling the PIL on my mac having to create a symbolic link to > libjpeg.so.6 or something. It was bizarre but worked fine afterwards. > > -- > Andrew Gwozdziewycz <[EMAIL PROTECTED]> > http://ihadagreatview.org > http://plasticandroid.org > -- > http://mail.python.org/mailman/listinfo/python-list > -- Amit Khemka -- onyomo.com Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
ordered sets operations on lists..
Hello, Is there a *direct* way of doing set operations on lists which preserve the order of the input lists ? For Ex. l1 = [1, 5, 3, 2, 4, 7] l2 = [3, 5, 10] and (l1 intersect l2) returns [5, 3] (and (l2 intersect l1) returns [3, 5]) thanks in advance, amit. -- Amit Khemka -- onyomo.com Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Split file into several and reformat
On 6/21/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi, > > I want to take read an input file (sels.txt) that looks like: > > Begin sels >sel1 = {1001, 1002, 1003, ... >... >1099} > >sel2 = {1001, 1008, 1009 ... >... >1299} > End sels > > And turn it into an output file for each of the "sels" in the input file, i.e > sel1.txt: Once you have read Bruno's pointers ! Have a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/521877 cheers, Amit Khemka -- Co-founder: OnYoMo website: www.onyomo.com wap-site: www.owap.in Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: import
On 7/6/07, jolly <[EMAIL PROTECTED]> wrote: > Hey guys, > > I'm rather new to python and i'm have trouble(as usual) Hope it becomes un-usual with Python ! > > I want to know if it is possible to change where 'import' looks > this will save me clogging up my python directory Yes. You can tell python where all to look for importing modules. import sys sys.path.append("/this/is/my/modules/path") > Thanks Welcome ! cheers, -- Amit Khemka website: www.onyomo.com wap-site: www.owap.in Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fetching a clean copy of a changing web page
On 7/16/07, John Nagle <[EMAIL PROTECTED]> wrote: > I'm reading the PhishTank XML file of active phishing sites, > at "http://data.phishtank.com/data/online-valid/"; This changes > frequently, and it's big (about 10MB right now) and on a busy server. > So once in a while I get a bogus copy of the file because the file > was rewritten while being sent by the server. > > Any good way to deal with this, short of reading it twice > and comparing? > If you have: 1. Ball park estimate of the size of XML 2. Some footers or "last tags" in the XML May be you can use the above to check the xml and catch the "bogus" ones ! cheers, -- Amit Khemka website: www.onyomo.com wap-site: www.owap.in Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Using Bessel Functions
Hi, I want to use Bessel functions in Python. I found on internet that package Scipy has a function jn(x), but I'm not able to use it. I am importing scipy and numpy for using it. But i'm getting an error "NameError: name 'j1' is not defined". Can anyone tell me what is the exact syntax for to use it. Thank you, Amit -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use imaageop.scale
On 23 May 2007 00:02:34 -0700, Bruce <[EMAIL PROTECTED]> wrote: > Hi, I want to compress a jpg file. e.g. a jpg file which has RGB band > (24bit per pixel), 100 * 100 size to 50 * 50 size. I > tried to use scale function in imageop module but failed. Any > suggestions about this? Thanks! Were there any exceptions/error-messasges ? Do you jpeg libraries installed for hadling jpeg format ? Cheers, -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use imaageop.scale
On 23 May 2007 18:58:28 -0700, Bruce <[EMAIL PROTECTED]> wrote: > On May 23, 5:31 pm, "Amit Khemka" <[EMAIL PROTECTED]> wrote: > > On 23 May 2007 00:02:34 -0700, Bruce <[EMAIL PROTECTED]> wrote: > > > > > Hi, I want to compress a jpg file. e.g. a jpg file which has RGB band > > > (24bit per pixel), 100 * 100 size to 50 * 50 size. I > > > tried to use scale function in imageop module but failed. Any > > > suggestions about this? Thanks! > > > > Were there any exceptions/error-messasges ? > > Do you jpeg libraries installed for hadling jpeg format ? > Amit & Marc, thank you very much. Now I used PIL instead and it works > fine. > But I still don't know how to complete this simple task with imageop > module. I think imageop moudle can handle raw images only, so if you want to use imageop you will need to convert jpeg images to raw format. Cheers, -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: function nested
On 5/24/07, Gigs_ <[EMAIL PROTECTED]> wrote: > def f(start): > stack = [] > def f1(start): > for fname in os.listdir(start): > path = os.path.join(start, fname) > if os.path.isfile(path): > stack.append(path) > else: > f1(path) > f1(start) > return stack > > > i feel s stupid right now > forgot to call f1 > > any comments how to make this better? os.walk is just the way for you ! Cheers, Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing Unicode object to Tuple Type
On 24 May 2007 04:45:32 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Can we have change a unicode string Type object to a Tuple type > object.. If so how *Loosely* speaking a tuple is a collection of multiple objects. So what are the objects that you want to put in that tuple ?! Or do you want to store the unicode string as one of the member in a tuple ? In which case you can just do it the obvious way (though i guess thats not the question you asked)! Cheers, Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Web Archtecture using tow layers in Phyton
On 5/23/07, Wagner Garcia Campagner <[EMAIL PROTECTED]> wrote: > Hello, > > I need to develop an web applications that meet the following requirements: > > - 2 layers: the first one is the user interface (browser) and the second one > is the interaction with the operacional system of the server. > - the second layer must be developed using Python. > > I'd like to know if it is possible to implement this system... making the > second layer using python and the first layer using another web technologies > like AJAX for example. Yes, It is very much possible and you will find the quite a few of such impementations . > Does anybody have any experience in developing python web applications? > Maybe send me some links or documentation about it... Search this news-group or web for "python web framework" and you can choose one based on your specific needs. ( some names that often pop up are: django, cherrypy, webware, pylons etc) > The final goal is to make diferent user interfaces (layer 1) that can > integrate with the second layer... for example, one web interface and one > local interface using python+qt (example)... i don't know if this is > possible and how can this be implemented... any help is aprreciated... Read the documentation of the framework ( if any) you choose to work with you may find templating system useful. For standalone app you can look at wxPython, which can communicate to your server at some port. Cheers, -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Xml parser
On 5/24/07, ashish <[EMAIL PROTECTED]> wrote: > Hi All, > > I want to know weather is there any api available in python for parsing > xml(XML parser) Checkout cElementTree . Cheers, -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie help understanding...
On 26 May 2007 00:23:32 -0700, mark <[EMAIL PROTECTED]> wrote: > Hi I am trying to get a piece of code to work based on an exercise in > a book. Any help appreciated. Can someone please explain what is going > on here. > > I am trying to read from a text file a list of cards with the > following format and sort firstly by suit and then by rank > > h 1 > d 2 > c 5 > s 9 > h2 > d3 > > etc... > > I get the following error; > Traceback (most recent call last): > File "F:/###UNI###/ITC106/ass2/cardread.py", line 25, in > t.append( t[0] + 400 ) > AttributeError: 'str' object has no attribute 'append' > def read_cards(filename): > cards = [] > for card in open(filename, 'r'): > cards.append(card.strip()) > return cards > > # read the deck of cards from a file > filename = 'cards.txt' > cards = read_cards(filename) > > > for t in read_cards(filename): > if t[1] == 'h': > t.append( t[0] + 100 ) > elif t[1] == 'd': > t.append( t[0] + 200 ) > elif t[1] == 'c': > t.append( t[0] + 300 ) > else: > t.append( t[0] + 400 ) In read_cards function you are appending a string in the list 'cards' , where i guess you wanted to append a list of suit and rank in list cards. def read_cards(filename): cards = [] for card in file(filename): cards.append(cards.split()) # i assume that suit and rank is separated by white space return cards or better still cards = [card.split() for card in file(filename)] Cheers, Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Filtering content of a text file
On 7/27/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello All, > > I'd greatly appreciate if you can take a look at the task I need help > with. > > It'd be outstanding if someone can provide some sample Python code. > > Thanks a lot, > > Ira > > --- > Problem > --- > > I am working with 30K+ record datasets in flat file format (.txt) that > look like this: > > //-+alibaba sinage > //-+amra damian//_9 > //-+anix anire//_ > //-+borom > //-+bokima sun drane > //-+ciren > //-+cop calestieon eded > //-+ciciban > //-+drago kimano sole > > > The records start with the same string (in the example //-+) wich is > followed by another string of characters taht's changing from record > to record. > > I am working on one file at the time and for each file I need to be > able to do the following: > > a) By looping thru the file the program should isolate all records > that have letter a following the //-+ > b) The isolated dataset will contain only records that start with //- > +a > c) Save the isolated dataset as flat flat text file named a.txt > d) Repeat a), b) and c) for all letters of english alphabet (a thru z) > and numerical values (0 thru 9) Well that should be easy if you take a look at methods in "string" module: A rough sketch would be : import string # import string module alnums = list(string.lowercase+string.digits) # create a list of alphabets and digits for alnum in alnums: outfile = open(alnum+'.txt', 'w') for line in file("myrecords.txt"): # iterate over the records if line.startswith("//-+"+alnum): # check your condition # write the matches to a file outfile.write(line) outfile.close() However rather than looping over the file for each alnum you may just iterate over the file, and check the starting characters (if len(line) > 4:ch=line[4]) , and if it is alnum then process it. Cheers, -- Amit Khemka website: www.onyomo.com wap-site: www.owap.in Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging module gives duplicate log entries
On 8/21/07, Shiao <[EMAIL PROTECTED]> wrote: > Hi, > I am getting duplicate log entries with the logging module. > > The following behaves as expected, leading to one log entry for each > logged event: > > logging.basicConfig(level=logging.DEBUG, filename='/tmp/foo.log') > > But this results in two entries for each logged event: > > applog = logging.getLogger() > applog.setLevel(logging.DEBUG) > hdl = logging.FileHandler('/tmp/foo.log') > applog.addHandler(hdl) > You need to remove the handler from the logging object # remove the handler once you are done applog.removeHandler(hdl) Cheers, amit. Amit Khemka website: www.onyomo.com wap-site: www.owap.in Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: for statement on empty iterable
On 8/22/07, james_027 <[EMAIL PROTECTED]> wrote: > hi Paul, > > > > > That doesn't crash or anything like that, but it also doesn't > > set the index variable, which can cause confusion in some situations. > > Thanks for your quick answer ... Actually I was thinking how do I > access the index inside a for statement? Can you help Have a look at "enumerate", You can iterate over a list like: for i,x in enumerate(['a', 'b', 'c']): print i, x It prints: 0 a 1 b 2 c cheers, amit Amit Khemka website: www.onyomo.com wap-site: www.owap.in Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: 'module object is not callable'
On 9/3/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi > > I am new to Python and have recieved this error message when trying to > instantiate an object from a class from another file within the same > directory and wondered what I have done wrong. > > I have a Step.py class: > class Step(object) > def __init__(self, sName): > "Initialise a new Step instance" > self.sName = sName > self.depSteps = [] > self.remDepSteps = [] > self.isCompleted = 0 > > > Then I have created a new file within the same directory called > main.py: > > import Step > a = Step("magn") > > The following however generates the error > Traceback (most recent call last): > File "main.py", line 3, in ? > a = Step("magn") > TypeError: 'module' object is not callable > > If anyone could help point me in the right direction, how to fix this > problem it would be much appreciated. > Chris The exception is being raised as you are being confused about the names ie: you have a class named "Step" in a module named "Step.py" . And by importing the module the only "Step" python sees is the module not the names declared within the module. To access a name defined in the module you can do : example1: import Step a = Step.Step("magn") # It refers the name "Step" defined IN the module "Step" example 2: from Step import Step # You directly import the class ( and make the name visible in your name space) a = Step("magn") Also have a look at: http://effbot.org/zone/import-confusion.htm http://docs.python.org/ref/import.html Cheers, -- Amit Khemka website: www.onyomo.com wap-site: www.owap.in -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: 'module object is not callable'
On 9/3/07, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Amit Khemka a écrit : > (snip) > > The exception is being raised as you are being confused about the > > names ie: you have a class named "Step" in a module named "Step.py" . > > > Actually, the module is named 'Step', not 'Setp.py' !-) > > Yup, My Bad ! Thanks. -- Amit Khemka website: www.onyomo.com wap-site: www.owap.in -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: 'module object is not callable'
On 9/4/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Thanks guys. Changing to how Python does things has a lot of geting > used to! > Do any of you have any ideas on the best way to do the following > problem: > > Each loop I perform, I get a new list of Strings. > I then want to print these lists as columns adjacent to each other > starting with the first > created list in the first column and last created list in the final > column. > > If you need any more information, just let me know! > Cheers If I understand correctly what you may want is: >>> l = ['1', '2', '3', '4'] you can do: >>> print "\t".join(l) # lookup join method in string module, assuming "\t" as the delimiter or, >>> for i in l: print i, '\t' , # note the trailing "," If this is not what you want, post an example. Btw, Please post new issues in a separate thread. Cheers, -- Amit Khemka website: www.onyomo.com wap-site: www.owap.in -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: 'module object is not callable'
On 9/4/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > On Sep 4, 11:24 am, "Amit Khemka" <[EMAIL PROTECTED]> wrote: > > On 9/4/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > > Thanks guys. Changing to how Python does things has a lot of geting > > > used to! > > > Do any of you have any ideas on the best way to do the following > > > problem: > > > > > Each loop I perform, I get a new list of Strings. > > > I then want to print these lists as columns adjacent to each other > > > starting with the first > > > created list in the first column and last created list in the final > > > column. > > > > > If you need any more information, just let me know! > > > Cheers > > > > If I understand correctly what you may want is: > > > > >>> l = ['1', '2', '3', '4'] > > > > you can do: > > > > >>> print "\t".join(l) # lookup join method in stringmodule, > > > > assuming "\t" as the delimiter > > > > or, > > > > >>> for i in l: > > > > print i, '\t' , # note the trailing "," > > > > If this isnotwhat you want, post an example. > > > > Btw, Please post new issues in a separate thread. > > > > Cheers, > > -- > > > > Amit Khemka > > website:www.onyomo.com > > wap-site:www.owap.in > > I think that is very similar to what I want to do. > Say I had lists a = ["1" , "2", "3"] b = ["4", "5", "6"] c = ["7", > "8", "9"] > Stored in another list d = [a,b,c] > I want the printed output from d to be of the form: > 1 4 7 > 2 5 8 > 3 6 9 > > >From what I am aware, there is no table module to do this. The '\t' > operator looks like it can allow this, > I am playing with it at the moment, although going for my lunch break > now! Have a look at function 'zip' or function 'izip' in module "itertools" . -- Amit Khemka website: www.onyomo.com wap-site: www.owap.in -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing lists in columns
On 9/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Thanks guys, I really appreciate it. I have never used google groups > before and am so impressed with how helpful you all are. It is also lovely > that none of you mock my little knowledge of Python but just want to > improve it. And we are proud of it ! > I have another question in relation to the izip_longest function (I > persume > this should be within the same topic). > Using this funciton, is there a way to manipulate it so that the > columns can be formated > tabular i.e. perhaps using something such as str(list).rjust(15) > because currently the columns > overlap depending on the strings lengths within each column/list of > lists. i.e. my output is > currently like: > > bo, daf, da > pres, ppar, xppc > magnjklep, *, dsa > *, *, nbi > > But I want it justified, i.e: > > bo , daf, da > pres , ppar, xppc > magnjklep,*, dsa > *,*, nbi You can format the output while "print"ing the table. Have a look at: http://www.python.org/doc/current/lib/typesseq-strings.html example: for tup in izip_longest(*d, **dict(fillvalue='*')): print "%15s, %15s, %15s" %tup # for a tuple of length 3, you can generalize it > I am struggling to understand how the izip_longest function works > and thus don't really know how it could be manipulated to do the > above. > It would be much apprecited if somoene could also explain how > izip_function > works as I don't like adding code into my programs which I struggle to > understand. > Or perhaps I have to pad out the lists when storing the Strings? > > Any help would be much appreciated. This is an example of "generator" functions, to understand what they are and how they work you can: 1. web-search for "python generators" 2. have a look at "itertools" module, for more generators -- Amit Khemka website: www.onyomo.com wap-site: www.owap.in -- http://mail.python.org/mailman/listinfo/python-list
Re: Looping through File Question
On 9/5/07, Francesco Guerrieri <[EMAIL PROTECTED]> wrote: > On 9/5/07, planetmatt <[EMAIL PROTECTED]> wrote: > > I am a Python beginner. I am trying to loop through a CSV file which > > I can do. What I want to change though is for the loop to start at > > row 2 in the file thus excluding column headers. > > > > At present I am using this statement to initiate a loop though the > > records: > > > > for line in f.readlines(): > > > > How do I start this at row 2? > > > > you can simply call (and maybe throw away) f.readline() a single time before > looping. > If the lenght of the first line is fixed, you can also use f.seek to start > reading from the second row. > > francesco Btw, if you are trying to read a csv file and parse it, you can save some work .. have a look at "csv" module ! -- Amit Khemka website: www.onyomo.com wap-site: www.owap.in -- http://mail.python.org/mailman/listinfo/python-list
Re: Using wild character
On 9/6/07, Sreeraj <[EMAIL PROTECTED]> wrote: > hi, > > I am a beginner in Python. I wish to know how can i filter a list of > strings using wild characters.ie > Lets say i have list countries = > ["india","africa","atlanta","artica","nigeria"]. I need only the list > of string starting with 'a'. There are a few ways of doing so. For some simple operations there are functions on the strings, If you want some more complex "filtering" then have a look at Python's regular expression module "re". example: >>> l = ["india","africa","atlanta","artica","nigeria"] >>> al = [c for c in l if c.startswith('a')] # this is a list comprehension >>> al ['africa', 'atlanta', 'artica'] To know more about list comprehensions, have a look at: http://docs.python.org/tut/node7.html#SECTION00714 Methods on strings: http://docs.python.org/lib/string-methods.html#string-methods Btw, not all of names in your list are countries ! Cheers, -- Amit Khemka website: www.onyomo.com wap-site: www.owap.in -- http://mail.python.org/mailman/listinfo/python-list