Questions about os.waitpid(pid, options) on windows
It seems that waitpid take process handle instead of process id as the first parameter on Windows. On Unices platform, the first parameter is process id. This interface is a little bit confusing. What's the purpose for such a design? Thanks a lot, Fan -- http://mail.python.org/mailman/listinfo/python-list
How to dynamicly define function and call the function?
I want to define some function in python script dynamicly and call
them later, but I get some problem. I have tried the following:
##
# code
##
class test:
def __init__(self):
exec("def dfunc(msg):\n\tprint msg\nprint 'exec def function'")
dfunc('Msg in init ...') # it work
def show(self, msg):
dfunc(msg) # doesn't work !
exec('dfunc(msg)') # doesn't work too!
d = test()
d.show('hello')
###
#output
##
exec def function
Msg in init ...
Traceback (most recent call last):
File "test.py", line 10, in ?
d.show('hello')
File "test.py", line 7, in show
dfunc(msg)
NameError: global name 'dfunc' is not defined
##
I think this maybe cause by the scope of function definition, for the
first call of 'dfunc' in __init__ work. So I tried to define the
function as a member function of class 'test', but this time even the
first call doesn't work:
##
# code
##
class test:
def __init__(self):
exec("def dfunc(self,msg):\n\tprint msg\nprint 'exec def function'")
self.dfunc('Msg in init ...')
def show(self, msg):
exec("self.dfunc(msg)")
d = test()
d.show('hello')
###
#output
##
exec def function
Traceback (most recent call last):
File "test.py", line 9, in ?
d = test()
File "test.py", line 4, in __init__
self.dfunc('Msg in init ...')
AttributeError: test instance has no attribute 'dfunc'
##
Is there any way I can solve this problem?
Regards
- FAN
--
http://mail.python.org/mailman/listinfo/python-list
extract rar
Hello everyone, I am wondering is there any way to extract rar files by python without WinRAR software? I tried Archive() and patool, but seems they required the WinRAR software. Thanks, Regards, Jianling -- https://mail.python.org/mailman/listinfo/python-list
Re: extract rar
Thanks, but the problem is that I am not allowed to install any software in my office PC, even free software. Normally, I use zip files but this time I need to extract a rar file. I don't like to go to IT guys because it takes time. That's why I am looking for an alternative way without installing other software. Thanks, On 1 April 2016 at 13:37, Albert-Jan Roskam wrote: > > > >> Date: Fri, 1 Apr 2016 13:22:12 -0600 >> Subject: extract rar >> From: [email protected] >> To: [email protected] >> >> Hello everyone, >> >> I am wondering is there any way to extract rar files by python without >> WinRAR software? >> >> I tried Archive() and patool, but seems they required the WinRAR software. > > Perhaps 7-zip in a Python subprocess: > http://superuser.com/questions/458643/unzip-rar-from-command-line-with-7-zip/464128 > -- Jianling Fan 樊建凌 -- https://mail.python.org/mailman/listinfo/python-list
REMOVE ME
-- https://mail.python.org/mailman/listinfo/python-list
about special characters
Hello everyone, I am trying to use python 27 copying some of my folders and files to another directory. My code works good for other files but I have some problem to copy files that have some special characters in the filename. like filenames contain Greek "δ" or latin "š". it always gave a error that "No such file or directory:" Any help will be appreciate! Thanks! Regards, Jianling -- https://mail.python.org/mailman/listinfo/python-list
Re: about special characters
Hello everyone,
Thanks very much for all your replies and sorry for the inconvience.
This is my first time to post question in this list.
I am using python 2.7 in Windows 7 Enterprise version.
Here is the the filename that cause the problem: "Decock-2013-On the
potential of δ18O and δ15N.pdf"
When I delete the "δ" in the filename, the script works good.
Here is the output:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> runfile('P:/sync.py', wdir='P:')
Traceback (most recent call last):
File "", line 1, in
File
"C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",
line 699, in runfile
execfile(filename, namespace)
File
"C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",
line 74, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "P:/sync.py", line 50, in
sync_files(src, dest)
File "P:/sync.py", line 43, in sync_files
sync(dir_cmp)
File "P:/sync.py", line 20, in sync
shutil.rmtree(f_right)
File "C:\Python27\lib\shutil.py", line 236, in rmtree
onerror(os.listdir, path, sys.exc_info())
File "C:\Python27\lib\shutil.py", line 234, in rmtree
names = os.listdir(path)
WindowsError: [Error 3] The system cannot find the path specified:
'P:/mystuff\\Decock-2013-On the potential of d18O and d15N.pdf/*.*'
Here is my code to do this work: I am using this script to sync my
files between different disks.
#coding=utf-8
import filecmp, shutil, os, sys
SRC = r'C:/Disk/mystuff'
DEST = r'P:/mystuff'
IGNORE = ['Thumbs.db']
def get_cmp_paths(dir_cmp, filenames):
return ((os.path.join(dir_cmp.left, f),
os.path.join(dir_cmp.right, f)) for f in filenames)
def sync(dir_cmp):
for f_left, f_right in get_cmp_paths(dir_cmp, dir_cmp.right_only):
if os.path.isfile(f_right):
os.remove(f_right)
else:
shutil.rmtree(f_right)
print('delete %s' % f_right)
for f_left, f_right in get_cmp_paths(dir_cmp,
dir_cmp.left_only+dir_cmp.diff_files):
if os.path.isfile(f_left):
shutil.copy2(f_left, f_right)
else:
shutil.copytree(f_left, f_right)
print('copy %s' % f_left)
for sub_cmp_dir in dir_cmp.subdirs.values():
sync(sub_cmp_dir)
def sync_files(src, dest, ignore=IGNORE):
if not os.path.exists(src):
print('= =b Please check the source directory was exist')
print('- -b Sync file failure !!!')
return
if os.path.isfile(src):
print('#_# We only support for sync directory but not a single
file,one file please do it by yourself')
print('- -b Sync file failure !!!')
return
if not os.path.exists(dest):
os.makedirs(dest)
dir_cmp = filecmp.dircmp(src, dest, ignore=IGNORE)
sync(dir_cmp)
print('^_^ Sync file finished!')
if __name__ == '__main__':
src, dest = SRC, DEST
if len(sys.argv) == 3:
src, dest = sys.argv[1:3]
sync_files(src, dest)
Thanks again!
On 29 April 2016 at 19:01, Steven D'Aprano wrote:
> On Sat, 30 Apr 2016 09:33 am, Jianling Fan wrote:
>
>> Hello everyone,
>>
>> I am trying to use python 27 copying some of my folders and files to
>> another directory.
>> My code works good for other files but I have some problem to copy
>> files that have some special characters in the filename. like
>> filenames contain Greek "δ" or latin "š".
>> it always gave a error that "No such file or directory:"
>>
>> Any help will be appreciate!
>
> Please put yourself in our shoes. Read your message above, and, imagine that
> you know NOTHING else about your program than what you write above. What
> answer would you give?
>
> Please tell us what you have actually done. How do you copy the files? How
> do you enter the file names? What OS are you using?
>
>
>
> --
> Steven
>
> --
> https://mail.python.org/mailman/listinfo/python-list
--
Jianling Fan
樊建凌
--
https://mail.python.org/mailman/listinfo/python-list
Re: about special characters
Oh, it works!
This is the simplest and best way!
Thanks very much!
On 30 April 2016 at 13:42, MRAB wrote:
> On 2016-04-30 19:13, Jianling Fan wrote:
>>
>> Hello everyone,
>>
>> Thanks very much for all your replies and sorry for the inconvience.
>> This is my first time to post question in this list.
>>
>> I am using python 2.7 in Windows 7 Enterprise version.
>>
>> Here is the the filename that cause the problem: "Decock-2013-On the
>> potential of δ18O and δ15N.pdf"
>> When I delete the "δ" in the filename, the script works good.
>>
>> Here is the output:
>>
>> Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
>> (Intel)] on win32
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>>
>>>>> runfile('P:/sync.py', wdir='P:')
>>
>> Traceback (most recent call last):
>> File "", line 1, in
>> File
>> "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",
>> line 699, in runfile
>> execfile(filename, namespace)
>> File
>> "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",
>> line 74, in execfile
>> exec(compile(scripttext, filename, 'exec'), glob, loc)
>> File "P:/sync.py", line 50, in
>> sync_files(src, dest)
>> File "P:/sync.py", line 43, in sync_files
>> sync(dir_cmp)
>> File "P:/sync.py", line 20, in sync
>> shutil.rmtree(f_right)
>> File "C:\Python27\lib\shutil.py", line 236, in rmtree
>> onerror(os.listdir, path, sys.exc_info())
>> File "C:\Python27\lib\shutil.py", line 234, in rmtree
>> names = os.listdir(path)
>> WindowsError: [Error 3] The system cannot find the path specified:
>> 'P:/mystuff\\Decock-2013-On the potential of d18O and d15N.pdf/*.*'
>>
>>
>> Here is my code to do this work: I am using this script to sync my
>> files between different disks.
>>
>> #coding=utf-8
>>
>> import filecmp, shutil, os, sys
>>
>> SRC = r'C:/Disk/mystuff'
>> DEST = r'P:/mystuff'
>>
>> IGNORE = ['Thumbs.db']
>>
>> def get_cmp_paths(dir_cmp, filenames):
>> return ((os.path.join(dir_cmp.left, f),
>> os.path.join(dir_cmp.right, f)) for f in filenames)
>>
>> def sync(dir_cmp):
>> for f_left, f_right in get_cmp_paths(dir_cmp, dir_cmp.right_only):
>> if os.path.isfile(f_right):
>> os.remove(f_right)
>> else:
>> shutil.rmtree(f_right)
>> print('delete %s' % f_right)
>> for f_left, f_right in get_cmp_paths(dir_cmp,
>> dir_cmp.left_only+dir_cmp.diff_files):
>> if os.path.isfile(f_left):
>> shutil.copy2(f_left, f_right)
>> else:
>> shutil.copytree(f_left, f_right)
>> print('copy %s' % f_left)
>> for sub_cmp_dir in dir_cmp.subdirs.values():
>> sync(sub_cmp_dir)
>>
>> def sync_files(src, dest, ignore=IGNORE):
>> if not os.path.exists(src):
>> print('= =b Please check the source directory was exist')
>> print('- -b Sync file failure !!!')
>> return
>> if os.path.isfile(src):
>> print('#_# We only support for sync directory but not a single
>> file,one file please do it by yourself')
>> print('- -b Sync file failure !!!')
>> return
>> if not os.path.exists(dest):
>> os.makedirs(dest)
>> dir_cmp = filecmp.dircmp(src, dest, ignore=IGNORE)
>> sync(dir_cmp)
>> print('^_^ Sync file finished!')
>>
>> if __name__ == '__main__':
>> src, dest = SRC, DEST
>> if len(sys.argv) == 3:
>> src, dest = sys.argv[1:3]
>> sync_files(src, dest)
>>
> [snip]
> You're using bytestrings (str). As soon as you step out of the ASCII
> range, you can face problems with which encoding it's using.
>
> The simplest fix is to switch to using Unicode.
>
> Start with this change:
>
> SRC = ur'C:/Disk/mystuff'
> DEST = ur'P:/mystuff'
>
> --
> https://mail.python.org/mailman/listinfo/python-list
--
Jianling Fan
樊建凌
--
https://mail.python.org/mailman/listinfo/python-list
Re: python
It seems like that python was already installed in your computer. Please check . On 11 January 2016 at 14:45, Sean Melville wrote: > I don't believe it's xp, it's a new laptop > > > >> On 11 Jan 2016, at 20:33, Cameron Simpson wrote: >> >>> On 11Jan2016 19:17, Sean Melville wrote: >>> I've downloaded python 3.5.1 but when I try and open it always says that I >>> have to either uninstall it, repair it or modify it. However, I've tried >>> all of them and it still doesn't work. >> >> On what operating system are you trying to install it? >> >> If you are using XP you need to download Python 3.4; Python 3.5 is not >> compatible with it. >> >> Cheers, >> Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: what can i do to improve my skill after finished python course on codecademy
在 2014年11月2日星期日UTC+8上午8时31分39秒,Grant Edwards写道: > On 2014-11-01, alister wrote: > > "The IETF motto is 'rouch consesus and running code'" > > -- Scott Bradner (Open Sources, 1999 O'Reilly and Associates) > > I don't get it, and googling didn't help. What is "rouch" consensus? > > -- > Grant Thanks for your help, but i have no idea to find a project that i can complete,i am now in perplexed for what to do -- https://mail.python.org/mailman/listinfo/python-list
python client call Java server by xmlrpc
Hi all
I have xmlrpc server written in Java, and it has a method like
Fun( vector, vector), the vector is array of user-defined object, which is
a class extends HashMap.
And I call it like:
server = xmlrpclib.ServerProxy("http://myserver";)
server.Fun( [ {"0.5":0.1}], [ ] )
It always fails with error
'No method matching arguments: , [Ljava.lang.Object;, [Ljava.lang.Object;
'
Does anyone use this before? It troubles me some days.
Thanks a lot.
Diana
--
https://mail.python.org/mailman/listinfo/python-list
Re: python client call Java server by xmlrpc
Thanks dieter, The issue is solved. I use SmartSniff to get the xml message send by java client, and python client, find the difference. Define a new class: class MyData(object): def __init__(self,myKey,myValue): self.Key = myKey self.Value = myValue and use this object as parameter, then the server return correct reply. para = MyData(0.5,0.01) server.Fun([para ], [ ] ) From: dieter To: [email protected] Date: 01/23/2015 03:26 PM Subject: Re: python client call Java server by xmlrpc Sent by: "Python-list" [email protected] writes: > I have xmlrpc server written in Java, and it has a method like > > Fun( vector, vector), the vector is array of user-defined object, which is > a class extends HashMap. > > And I call it like: > > server = xmlrpclib.ServerProxy("http://myserver";) > > server.Fun( [ {"0.5":0.1}], [ ] ) > > It always fails with error > > 'No method matching arguments: , [Ljava.lang.Object;, [Ljava.lang.Object; > ' > Does anyone use this before? It troubles me some days. The standard XML-RPC protocol knows only about a very small set of types. Extensions are required to pass on more type information. The (slightly confusing) error message (you got) indicates that the XML-RPC framework on the server side has not correctly recognized the types of the incoming parameters: it should recognize the "[]" (as this is a standard type) (and maybe the open "[" indicates that it has indeed) but apparently, it got the content elements only as generalized "Object"s not something specific (extending "HashMap"). The "xmlrpclib" in the Python runtime libary does not support extensions to pass on additional type information (as far as I know). This might indicate that you cannot use Python's "xmlrpclib" out of the box to interact with your Java implemented XML-RPC service. I would approach the problem as follows. Implement a Java based XML-RPC client for your service. Should this fail, then your service implementation has too complex types for XML-RPC (and you must simplify them). Should you succeed, you can use a tcp logger (or maybe debugging tools of the Java libary implementing XML-RPC) to determine the exact messages exchanged between client and server. This way, you can learn how your Java libraries pass on non standard type information. You can then derive a new class from Python's "xmlrpclib" and implement there this type information passing extension (apparently used by your Java libaries). -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
PyImport_Import() failed
Hello, I'm new to Python.I want to embed Python interpreter into my C++ application powered by Borland C++ Builder 2006. I have written some C++ code in order to evaluate Python script file, but PyImport_Import() calls
failed.I really don't know what's wrong with my cpp code.It always return a NULL value. Any advice is appreciated!int TPython::ExecuteScript(const char * pszFileName){ PyObject *pFileName, *pModule, *pDict, *pFunc;
PyObject *pArgs, *pValue; pFileName = PyString_FromString(pszFileName); /* Error checking of pFileName left out */ if(!pFileName) { trace1(("pFileName == NULL "));
} pModule = PyImport_Import(pFileName); // always failed, returned NULL:( Py_DECREF(pFileName); if (pModule != NULL) {
} else { PyErr_Print(); trace1(("Failed to load \"%s\"\n", pszFileName)); return 1; }
return 0;}
--
http://mail.python.org/mailman/listinfo/python-list
Re: shuffling elements of a list
On 30 May 2006 20:18:19 -0700, greenflame <[EMAIL PROTECTED]> wrote: > Second of all, I would like to have > other methods of shuffling, prefererably riffle shuffling and just > plain randomly arranging the elements of the list. The random module has a `shuffle' method. It "Shuffle the sequence x in place". It may be help for you -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting key presses
On 2006-06-18 13:20:06, tylertacky write: >Ok, I'm pretty new to python, so this might be a stupid question. I'm >trying to write a simple text-based pong clone, and I can't figure out >how to read key presses to move the paddles. I just need something that >does the same thing as getch() and kbhit(). I can't use those because >their windows only, and I'm running Linux. > >Someone suggested using curses, but that does crazy things with my >output, and leaves the terminal unusable after the program closes. > >-- >http://mail.python.org/mailman/listinfo/python-list The python.org site has a faq about getting keystroke. It uses termios and fcntl modules. Here's the link: http://www.python.org/doc/faq/library/#how-do-i-get-a-single-keypress-at-a-time Hope it can help you! - Fan Zhang -- http://mail.python.org/mailman/listinfo/python-list
Read an image from a URL and write it to the browser
I want to do something simple: read an image from an image URL and write the image to the browser in CGI style. I wrote a CGI script to do this (I'm new to Python) and got the following error: "FancyURLopener instance has no attribute 'tempcache'" in http://www.google.com/google_logo.jpg"; imgStream = urllib.urlopen(urlString) imgBuffer = imgStream.read() imgStream.close() print "Content-Type: image/jpeg" print print imgBuffer -- http://mail.python.org/mailman/listinfo/python-list
Re: Read an image from a URL and write it to the browser
On Dec 21, 7:25 am, Peter Otten <[email protected]> wrote: > McCoy Fan wrote: > > I want to do something simple: read an image from an image URL and > > write the image to the browser in CGI style. > > > I wrote a CGI script to do this (I'm new to Python) and got the > > following error: > > > "FancyURLopener instance has no attribute 'tempcache'" in > method FancyURLopener.__del__ of > > I have no idea what that error means and neither does Google. > > > Any idea where I went wrong in the code below? > > import urllib > > > urlString = "http://www.google.com/google_logo.jpg"; > > imgStream = urllib.urlopen(urlString) > > imgBuffer = imgStream.read() > > imgStream.close() > > print "Content-Type: image/jpeg" > > print > > print imgBuffer > > Your script runs without error here, but I can provoke the attribute error > by passing an invalid proxies argument to urlopen(): > > $ python -c"import urllib; urllib.urlopen('whatever', proxies=42)" > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.5/urllib.py", line 75, in urlopen > opener = FancyURLopener(proxies=proxies) > File "/usr/lib/python2.5/urllib.py", line 609, in __init__ > URLopener.__init__(self, *args, **kwargs) > File "/usr/lib/python2.5/urllib.py", line 117, in __init__ > assert hasattr(proxies, 'has_key'), "proxies must be a mapping" > AssertionError: proxies must be a mapping > Exception exceptions.AttributeError: "FancyURLopener instance has no > attribute 'tempcache'" in > ignored > > Please post your complete traceback, Python version, and OS to allow for a > more detailed diagnosis. > > You can also try to run your script with > > > imgStream = urllib.urlopen(urlString) > > changed to > > imgStream = urllib.urlopen(urlString, proxies={}) > > to bypass the code in which I suppose the failure to occur. > > Peter I appreciate your response. Thank you. After reading your reply, I realized this must be related to the fact that I am running this script on Google App Engine. It turns out, App Engine does not allow direct socket communication so urllib is not allowed. Instead they provide their own library called urlfetch. So my script should look something like this: from google.appengine.api import urlfetch print 'Content-Type: text/plain' print '' result = urlfetch.fetch('http://www.google.com/google_logo.jpg') print result.content I haven't been able to get it to work yet but at least I'm heading in the right direction now. I'll keep digging. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Why threading.Thread has no detach method
Does this mean terminated threads will automatically release all resouce? -- http://mail.python.org/mailman/listinfo/python-list
Re: NoSQL Movement?
Jonathan Gardner wrote: I see it as a sign of maturity with sufficiently scaled software that they no longer use an SQL database to manage their data. At some point in the project's lifetime, the data is understood well enough that the general nature of the SQL database is unnecessary. I am really struggling to understand this concept. Is it the normalised table structure that is in question or the query language? Could you give some sort of example of where SQL would not be the way to go. The only things I can think of a simple flat file databases. -- http://mail.python.org/mailman/listinfo/python-list
