use python to split a video file into a set of parts

2013-05-07 Thread iMath
I use the following python code to split a FLV video file into a set of parts 
,when finished ,only the first part video can be played ,the other parts are 
corrupted.I wonder why and Is there some correct ways to split video files

import sys, os
kilobytes = 1024
megabytes = kilobytes * 1000
chunksize = int(1.4 * megabytes)   # default: roughly a floppy

print(chunksize , type(chunksize ))

def split(fromfile, todir, chunksize=chunksize):
if not os.path.exists(todir):  # caller handles errors
os.mkdir(todir)# make dir, read/write parts
else:
for fname in os.listdir(todir):# delete any existing files
os.remove(os.path.join(todir, fname))
partnum = 0
input = open(fromfile, 'rb')   # use binary mode on Windows
while True:# eof=empty string from read
chunk = input.read(chunksize)  # get next part <= chunksize
if not chunk: break
partnum += 1
filename = os.path.join(todir, ('part{}.flv'.format(partnum)))
fileobj  = open(filename, 'wb')
fileobj.write(chunk)
fileobj.close()# or simply open().write()
input.close()
assert partnum <=  # join sort fails if 5 digits
return partnum

if __name__ == '__main__':

fromfile = input('File to be split: ')   # input if clicked
todir= input('Directory to store part files:')
print('Splitting', fromfile, 'to', todir, 'by', chunksize)
parts = split(fromfile, todir, chunksize)
print('Split finished:', parts, 'parts are in', todir)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to detect the character encoding in a web page ?

2013-06-05 Thread iMath
在 2012年12月24日星期一UTC+8上午8时34分47秒,iMath写道:
> how to detect the character encoding  in a web page ?
> 
> such as this page 
> 
> 
> 
> http://python.org/

I found PyQt’s QtextStream can  very accurately detect the character encoding 
in a web page .
even for this bad page 

chardet and beautiful soup failed ,but QtextStream can get the right result .

here is my code 

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtNetwork  import *
import sys
def slotSourceDownloaded(reply):
redirctLocation=reply.header(QNetworkRequest.LocationHeader)
redirctLocationUrl=reply.url() if not redirctLocation else redirctLocation
print(redirctLocationUrl)
  
if (reply.error()!= QNetworkReply.NoError):
print('', reply.errorString())
return
  
content=QTextStream(reply).readAll()
if content=='':
print('-', 'cannot find any resource !')
return
 
print(content)
 
reply.deleteLater()
qApp.quit()
 
 
if __name__ == '__main__':
app =QCoreApplication(sys.argv)
manager=QNetworkAccessManager ()
url =input('input url :')
request=QNetworkRequest 
(QUrl.fromEncoded(QUrl.fromUserInput(url).toEncoded()))
request.setRawHeader("User-Agent" ,'Mozilla/5.0 (Windows NT 5.1) 
AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17 SE 2.X 
MetaSr 1.0')
manager.get(request)
manager.finished.connect(slotSourceDownloaded)
sys.exit(app.exec_())
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to detect the character encoding in a web page ?

2013-06-05 Thread iMath
在 2012年12月24日星期一UTC+8上午8时34分47秒,iMath写道:
> how to detect the character encoding  in a web page ?
> 
> such as this page 
> 
> 
> 
> http://python.org/

I found PyQt’s QtextStream can  very accurately detect the character encoding 
in a web page . 
even for this bad page 
http://www.qnwz.cn/html/yinlegushihui/magazine/2013/0524/425731.html
chardet and beautiful soup failed ,but QtextStream can get the right result . 

here is my code 

from PyQt4.QtCore import * 
from PyQt4.QtGui import * 
from PyQt4.QtNetwork  import * 
import sys 
def slotSourceDownloaded(reply): 
redirctLocation=reply.header(QNetworkRequest.LocationHeader) 
redirctLocationUrl=reply.url() if not redirctLocation else redirctLocation 
print(redirctLocationUrl) 
  
if (reply.error()!= QNetworkReply.NoError): 
print('', reply.errorString()) 
return 
  
content=QTextStream(reply).readAll() 
if content=='': 
print('-', 'cannot find any resource !') 
return 
  
print(content) 
  
reply.deleteLater() 
qApp.quit() 
  
  
if __name__ == '__main__': 
app =QCoreApplication(sys.argv) 
manager=QNetworkAccessManager () 
url =input('input url :') 
request=QNetworkRequest 
(QUrl.fromEncoded(QUrl.fromUserInput(url).toEncoded())) 
request.setRawHeader("User-Agent" ,'Mozilla/5.0 (Windows NT 5.1) 
AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17 SE 2.X 
MetaSr 1.0') 
manager.get(request) 
manager.finished.connect(slotSourceDownloaded) 
sys.exit(app.exec_())
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to detect the character encoding in a web page ?

2013-06-05 Thread iMath
在 2012年12月24日星期一UTC+8上午8时34分47秒,iMath写道:
> how to detect the character encoding  in a web page ?
> 
> such as this page 
> 
> 
> 
> http://python.org/

by the way  ,we cannot get character encoding programmatically from the mate 
data without knowing the  character encoding  ahead !
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to detect the character encoding in a web page ?

2013-06-09 Thread iMath
在 2012年12月24日星期一UTC+8上午8时34分47秒,iMath写道:
> how to detect the character encoding  in a web page ?
> 
> such as this page 
> 
> 
> 
> http://python.org/

Finally ,I found by using PyQt’s QtextStream , QTextCodec and chardet ,we can 
get a web page code more securely  
even for this bad page
http://www.qnwz.cn/html/yinlegushihui/magazine/2013/0524/425731.html 

this script 
http://www.flvxz.com/getFlv.php?url=aHR0cDojI3d3dy41Ni5jb20vdTk1L3ZfT1RFM05UYzBNakEuaHRtbA==

and this page without chardet in its source code 
http://msdn.microsoft.com/en-us/library/bb802962(v=office.12).aspx


from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtNetwork  import *
import sys
import chardet

def slotSourceDownloaded(reply):
redirctLocation=reply.header(QNetworkRequest.LocationHeader)
redirctLocationUrl=reply.url() if not redirctLocation else redirctLocation
#print(redirctLocationUrl,reply.header(QNetworkRequest.ContentTypeHeader))

if (reply.error()!= QNetworkReply.NoError):
print('', reply.errorString())
return

pageCode=reply.readAll()
charCodecInfo=chardet.detect(pageCode.data())

textStream=QTextStream(pageCode)

codec=QTextCodec.codecForHtml(pageCode,QTextCodec.codecForName(charCodecInfo['encoding']
 ))
textStream.setCodec(codec)
content=textStream.readAll()
print(content)

if content=='':
print('-', 'cannot find any resource !')
return

reply.deleteLater()
qApp.quit()


if __name__ == '__main__':
app =QCoreApplication(sys.argv)
manager=QNetworkAccessManager ()
url =input('input url :')
request=QNetworkRequest 
(QUrl.fromEncoded(QUrl.fromUserInput(url).toEncoded()))
request.setRawHeader("User-Agent" ,'Mozilla/5.0 (Windows NT 5.1) 
AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17 SE 2.X 
MetaSr 1.0')
manager.get(request)
manager.finished.connect(slotSourceDownloaded)
sys.exit(app.exec_())
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to detect the character encoding in a web page ?

2013-06-09 Thread iMath
在 2012年12月24日星期一UTC+8上午8时34分47秒,iMath写道:
> how to detect the character encoding  in a web page ?
> 
> such as this page 
> 
> 
> 
> http://python.org/

here is one thread that can help me understanding my code 
http://stackoverflow.com/questions/17001407/how-to-detect-the-character-encoding-of-a-web-page-programmatically/17009285#17009285
-- 
http://mail.python.org/mailman/listinfo/python-list


What’s the differences between these two pieces of code ?

2012-07-06 Thread iMath
What’s the differences between these two  pieces of code ?
(1)
for i in range(1, 7):
print(2 * i, end='   ')


(2)
for i in range(1, 7):
print(2 * i, end='   ')
print()


when executed both  respectively in Python shell ,I  get  the same effect . Who 
can tell me why  ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Does os.getcwd() and os.curdir have the same effect ?

2012-09-09 Thread iMath
Does os.getcwd() and os.curdir have the same effect ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there any difference between print 3 and print '3' in Python ?

2012-09-09 Thread iMath
在 2012年3月26日星期一UTC+8下午7时45分26秒,iMath写道:
> I know the print statement produces the same result when both of these two 
> instructions are executed ,I just want to know Is there any difference 
> between print 3 and print '3' in Python ?

thx everyone
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What’s the differences between these two pieces of code ?

2012-09-09 Thread iMath
在 2012年7月7日星期六UTC+8下午12时56分35秒,iMath写道:
> What’s the differences between these two  pieces of code ?
> 
> (1)
> 
> for i in range(1, 7):
> 
> print(2 * i, end='   ')
> 
> 
> 
> thx everyone
> 
> (2)
> 
> for i in range(1, 7):
> 
> print(2 * i, end='   ')
> 
> print()
> 
> 
> 
> 
> 
> when executed both  respectively in Python shell ,I  get  the same effect . 
> Who can tell me why  ?

-- 
http://mail.python.org/mailman/listinfo/python-list


regular expression : the dollar sign ($) work with re.match() or re.search() ?

2012-09-26 Thread iMath
I only know  the dollar sign ($) will match a pattern from the
end of a string,but which method does it work with ,re.match() or re.search()  ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does os.getcwd() and os.curdir have the same effect ?

2012-09-26 Thread iMath
On Sunday, September 9, 2012 9:39:28 PM UTC+8, Thomas Jollans wrote:
> On 09/09/2012 03:22 PM, iMath wrote: > Does os.getcwd() and os.curdir have 
> the same effect ? > Python 3.2.3 (default, May 3 2012, 15:51:42) [GCC 4.6.3] 
> on linux2 Type "help", "copyright", "credits" or "license" for more 
> information. >>> import os >>> os.getcwd() '/home/tjol' >>> os.curdir '.' >>> 
> No. Both refer to the current directory, but os.curdir is not an absolute 
> path, so you can't chdir() to it later and expect to land it the original 
> directory.

get it ,thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212.

2012-09-28 Thread iMath
write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212.
-- 
http://mail.python.org/mailman/listinfo/python-list


where to view range([start], stop[, step])'s C implementation source code ?

2012-10-01 Thread iMath
where to view range([start], stop[, step])'s C implementation source code ?
-- 
http://mail.python.org/mailman/listinfo/python-list


To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ?

2012-10-08 Thread iMath
To get the accurate value of 1 - 0.999 ,how to implement the python 
algorithm ?
BTW ,Windows’s calculator get the accurate value ,anyone who knows how to 
implement it ?
-- 
http://mail.python.org/mailman/listinfo/python-list


how to use pyODBC to connect to MySql ,please give me a sample

2012-10-16 Thread iMath

 host name : localhost
user name:root
 password:19910512
database name : shopping
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where to view range([start], stop[, step])'s C implementation source code ?

2012-10-17 Thread iMath
On Monday, October 1, 2012 11:42:26 PM UTC+8, Ian wrote:
> On Mon, Oct 1, 2012 at 9:28 AM, iMath  wrote:
> 
> > where to view range([start], stop[, step])'s C implementation source code ?
> 
> 
> 
> http://hg.python.org/cpython/file/3f739f42be51/Objects/rangeobject.c

thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


How to only get a list of the names of the non-directory files in current directory ('.')?

2012-11-05 Thread iMath
How to only get a list of the names of the non-directory files in current 
directory ('.')?
(Note excluding its subdirectories ).

I need the code : )
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to only get a list of the names of the non-directory files in current directory ('.')?

2012-11-06 Thread iMath
在 2012年11月6日星期二UTC+8下午1时24分41秒,Chris Angelico写道:
> On Tue, Nov 6, 2012 at 4:19 PM, iMath  wrote:
> 
> > How to only get a list of the names of the non-directory files in current 
> > directory ('.')?
> 
> > (Note excluding its subdirectories ).
> 
> >
> 
> > I need the code : )
> 
> 
> 
> Start by getting a list of names of everything in the current directory.
> 
> 
> 
> Then filter that list by testing each one to see if it's a directory.
> 
> 
> 
> Tip: The second step can be done with os.path.isdir
> 
> 
> 
> Put some code together and try it. If you have trouble, post your
> 
> code, any exception traceback you get, and what you're having
> 
> difficulty with, and we'll go on from there.
> 
> 
> 
> Have fun!
> 
> 
> 
> ChrisA

how to get a list of names of everything in the current directory ?
-- 
http://mail.python.org/mailman/listinfo/python-list


UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

2012-12-06 Thread iMath
the following code originally from 
http://zetcode.com/databases/mysqlpythontutorial/
within the "Writing images" part .


import MySQLdb as mdb
import sys

try:
fin = open("Chrome_Logo.svg.png",'rb')
img = fin.read()
fin.close()

except IOError as e:

print ("Error %d: %s" % (e.args[0],e.args[1]))
sys.exit(1)


try:
conn = mdb.connect(host='localhost',user='testuser',
   passwd='test623', db='testdb')
cursor = conn.cursor()
cursor.execute("INSERT INTO Images SET Data='%s'" % \
mdb.escape_string(img))

conn.commit()

cursor.close()
conn.close()

except mdb.Error as e:

print ("Error %d: %s" % (e.args[0],e.args[1]))
sys.exit(1)


I port it to python 3 ,and also change 
fin = open("chrome.png") 
to 
fin = open("Chrome_Logo.png",'rb')
but when I run it ,it gives the following error :

Traceback (most recent call last): 
  File "E:\Python\py32\itest4.py", line 20, in 
mdb.escape_string(img))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid 
start byte

so how to fix it ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

2012-12-07 Thread iMath
在 2012年12月6日星期四UTC+8下午7时07分35秒,Hans Mulder写道:
> On 6/12/12 11:07:51, iMath wrote:
> 
> > the following code originally from 
> > http://zetcode.com/databases/mysqlpythontutorial/
> 
> > within the "Writing images" part .
> 
> > 
> 
> > 
> 
> > import MySQLdb as mdb
> 
> > import sys
> 
> > 
> 
> > try:
> 
> > fin = open("Chrome_Logo.svg.png",'rb')
> 
> > img = fin.read()
> 
> > fin.close()
> 
> > 
> 
> > except IOError as e:
> 
> > 
> 
> > print ("Error %d: %s" % (e.args[0],e.args[1]))
> 
> > sys.exit(1)
> 
> > 
> 
> > 
> 
> > try:
> 
> > conn = mdb.connect(host='localhost',user='testuser',
> 
> >passwd='test623', db='testdb')
> 
> > cursor = conn.cursor()
> 
> > cursor.execute("INSERT INTO Images SET Data='%s'" % \
> 
> > mdb.escape_string(img))
> 
> 
> 
> You shouldn't call mdb.escape_string directly.  Instead, you
> 
> should put placeholders in your SQL statement and let MySQLdb
> 
> figure out how to properly escape whatever needs escaping.
> 
> 
> 
> Somewhat confusingly, placeholders are written as %s in MySQLdb.
> 
> They differ from strings in not being enclosed in quotes.
> 
> The other difference is that you'd provide two arguments to
> 
> cursor.execute; the second of these is a tuple; in this case
> 
> a tuple with only one element:
> 
> 
> 
> cursor.execute("INSERT INTO Images SET Data=%s", (img,))
> 
> 
thanks,but it still doesn't work
> 
> > conn.commit()
> 
> > 
> 
> > cursor.close()
> 
> > conn.close()
> 
> > 
> 
> > except mdb.Error as e:
> 
> > 
> 
> > print ("Error %d: %s" % (e.args[0],e.args[1]))
> 
> > sys.exit(1)
> 
> > 
> 
> > 
> 
> > I port it to python 3 ,and also change 
> 
> > fin = open("chrome.png") 
> 
> > to 
> 
> > fin = open("Chrome_Logo.png",'rb')
> 
> > but when I run it ,it gives the following error :
> 
> > 
> 
> > Traceback (most recent call last): 
> 
> >   File "E:\Python\py32\itest4.py", line 20, in 
> 
> > mdb.escape_string(img))
> 
> > UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: 
> > invalid start byte
> 
> > 
> 
> > so how to fix it ?
> 
> 
> 
> Python 3 distinguishes between binary data and Unicode text.
> 
> Trying to apply string functions to images or other binary
> 
> data won't work.
> 
> 
> 
> Maybe correcting this bytes/strings confusion and porting
> 
> to Python 3 in one go is too large a transformation.  In
> 
> that case, your best bet would be to go back to Python 2
> 
> and fix all the bytes/string confusion there.  When you've
> 
> got it working again, you may be ready to port to Python 3.
> 
> 
> 
> 
> 
> Hope this helps,
> 
> 
> 
> -- HansM

-- 
http://mail.python.org/mailman/listinfo/python-list


where to view open() function's C implementation source code ?

2012-12-17 Thread iMath
where to view  open() function's C implementation source code ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where to view open() function's C implementation source code �

2012-12-17 Thread iMath
在 2012年12月18日星期二UTC+8下午1时35分58秒,Roy Smith写道:
> In article ,
> 
>  iMath  wrote:
> 
> 
> 
> > where to view  open() function's C implementation source code ?
> 
> 
> 
> http://www.python.org/download/releases/
> 
> 
> 
> Download the source for the version you're interested in.

but which python module is  open() in ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where to view open() function's C implementation source code �

2012-12-18 Thread iMath
在 2012å¹´12月19日星期三UTC+8上午4时57分37秒,[email protected]写道:
> On Monday, December 17, 2012 10:35:58 PM UTC-7, Roy Smith wrote:
> 
> > iMath  wrote:
> 
> > > where to view  open() function's C implementation source code ?
> 
> > http://www.python.org/download/releases/
> 
> > Download the source for the version you're interested in.
> 
> 
> 
> iMath:
> 
> 
> 
> There is no need to download the source.  You can browse the 
> 
> source code online.  For the v3.0.0 version of open():
> 
>   hg.python.org/cpython/file/bd8afb90ebf2/Modules/_io/_iomodule.c
> 
> 
> 
> For 2.7.3 I think what you want is the  builtin_open() function in 
> 
>   http://hg.python.org/cpython/file/70274d53c1dd/Python/bltinmodule.c
> 
> and the file object and open_the_file() function in
> 
>  http://hg.python.org/cpython/file/70274d53c1dd/Objects/fileobject.c
> 
> 
> 
> Hope this helps.

thanks very much !
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where to view open() function's C implementation source code �

2012-12-18 Thread iMath
在 2012å¹´12月19日星期三UTC+8上午4时57分37秒,[email protected]写道:
> On Monday, December 17, 2012 10:35:58 PM UTC-7, Roy Smith wrote:
> 
> > iMath  wrote:
> 
> > > where to view  open() function's C implementation source code ?
> 
> > http://www.python.org/download/releases/
> 
> > Download the source for the version you're interested in.
> 
> 
> 
> iMath:
> 
> 
> 
> There is no need to download the source.  You can browse the 
> 
> source code online.  For the v3.0.0 version of open():
> 
>   hg.python.org/cpython/file/bd8afb90ebf2/Modules/_io/_iomodule.c
> 
> 
> 
> For 2.7.3 I think what you want is the  builtin_open() function in 
> 
>   http://hg.python.org/cpython/file/70274d53c1dd/Python/bltinmodule.c
> 
> and the file object and open_the_file() function in
> 
>  http://hg.python.org/cpython/file/70274d53c1dd/Objects/fileobject.c
> 
> 
> 
> Hope this helps.

thanks very much !
-- 
http://mail.python.org/mailman/listinfo/python-list


how to detect the encoding used for a specific text data ?

2012-12-20 Thread iMath
 how to detect the encoding used for a specific text data ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to detect the encoding used for a specific text data ?

2012-12-20 Thread iMath
which package to use ?
-- 
http://mail.python.org/mailman/listinfo/python-list


redirect standard output problem

2012-12-20 Thread iMath
redirect standard output problem

why the result only print A but leave out 888 ?

import sys
class RedirectStdoutTo:

def __init__(self, out_new):
self.out_new = out_new
def __enter__(self):
sys.stdout = self.out_new
def __exit__(self, *args):
sys.stdout = sys.__stdout__


print('A')
with open('out.log', mode='w', encoding='utf-8') as a_file, 
RedirectStdoutTo(a_file):

print('B')
print('C')

print(888)
-- 
http://mail.python.org/mailman/listinfo/python-list


Pass and return

2012-12-20 Thread iMath
Pass and return
Are these two functions the same ?

def test():
return 
 
def test():
pass
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: redirect standard output problem

2012-12-22 Thread iMath
在 2012年12月21日星期五UTC+8下午3时24分10秒,Chris Angelico写道:
> On Fri, Dec 21, 2012 at 4:23 PM, iMath  wrote:
> 
> > redirect standard output problem
> 
> >
> 
> > why the result only print A but leave out 888 ?
> 
> 
> 
> No idea, because when I paste your code into the Python 3.3
> 
> interpreter or save it to a file and run it, it does exactly what I
> 
> would expect. A and 888 get sent to the screen, B and C go to the
> 
> file.
> 
> 
> 
> What environment are you working in? Python version, operating system,
> 
> any little details that just might help us help you.
> 
> 
> 
> ChrisA


 on WinXP + python32  

when I run it through command line ,it works ok ,but when I run it through IDLE 
, only print A but leave out 888
so why ?
-- 
http://mail.python.org/mailman/listinfo/python-list


how to detect the character encoding in a web page ?

2012-12-23 Thread iMath
how to detect the character encoding  in a web page ?
such as this page 

http://python.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


urllib.error.HTTPError: HTTP Error 403: Forbidden

2012-12-23 Thread iMath
>>> import urllib.request
>>> response = 
>>> urllib.request.urlopen('http://en.wikipedia.org/wiki/Internet_media_type')
Traceback (most recent call last):
  File "", line 1, in 
response = 
urllib.request.urlopen('http://en.wikipedia.org/wiki/Internet_media_type')
  File "C:\Python32\lib\urllib\request.py", line 138, in urlopen
return opener.open(url, data, timeout)
  File "C:\Python32\lib\urllib\request.py", line 375, in open
response = meth(req, response)
  File "C:\Python32\lib\urllib\request.py", line 487, in http_response
'http', request, response, code, msg, hdrs)
  File "C:\Python32\lib\urllib\request.py", line 413, in error
return self._call_chain(*args)
  File "C:\Python32\lib\urllib\request.py", line 347, in _call_chain
result = func(*args)
  File "C:\Python32\lib\urllib\request.py", line 495, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden


why this url generate error ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to detect the character encoding in a web page ?

2012-12-23 Thread iMath
在 2012年12月24日星期一UTC+8上午8时34分47秒,iMath写道:
> how to detect the character encoding  in a web page ?
> 
> such as this page 
> 
> 
> 
> http://python.org/

but how to let python do it for you ?

such as this page 

http://python.org/ 

how to  detect the character encoding in this web page by python ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to detect the character encoding in a web page ?

2012-12-23 Thread iMath
在 2012年12月24日星期一UTC+8上午8时34分47秒,iMath写道:
> how to detect the character encoding  in a web page ?
> 
> such as this page 
> 
> 
> 
> http://python.org/

but how to let python do it for you ? 

such as these 2 pages 

http://python.org/ 
http://msdn.microsoft.com/en-us/library/bb802962(v=office.12).aspx

how to  detect the character encoding in these 2 pages  by python ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to detect the character encoding in a web page ?

2012-12-23 Thread iMath
在 2012年12月24日星期一UTC+8上午8时34分47秒,iMath写道:
> how to detect the character encoding  in a web page ?
> 
> such as this page 
> 
> 
> 
> http://python.org/

but how to let python do it for you ? 

such as these 2 pages 

http://python.org/ 
http://msdn.microsoft.com/en-us/library/bb802962(v=office.12).aspx

how to  detect the character encoding in these 2 pages  by python ?
-- 
http://mail.python.org/mailman/listinfo/python-list


EOFError why print(e) cannot print out any information ?

2012-12-25 Thread iMath

why print(e) cannot print out any information ?

class user:
def __init__(self, x,y,z):
self.id = x
self.name = y
self.emailadd=z
def dispuser(self):
print('User ID: ', self.id)
print('User Name : ', self.name)
print('Email Address: ', self.emailadd)

f = open('UsersInfo.bin', 'wb')
n=int(input('How many users?'))
print('Enter ', n, 'numbers')
for i in range(0,n):
u=input('User ID: ')
n=input('User Name: ')
e=input('Email Address: ')
usrobj=user(u,n,e)
pickle.dump(usrobj,f)
f.close()
print('\nInformation of the users is:')
f = open('UsersInfo.bin','rb')
while True:
try:
usrobj = pickle.load(f)
except EOFError as e:
print(e)
break
else:

usrobj.dispuser()
f.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


need a url that its http response header that cotain 401 status code

2012-12-26 Thread iMath
I am going to do a  Basic Authentication ,
so I need a url 
 that its http response header that cotain 401 status code.
-- 
http://mail.python.org/mailman/listinfo/python-list


os.path.realpath(path) bug on win7 ?

2013-01-05 Thread iMath

os.path.realpath(path)  bug on win7 ?Temp.link is a Symbolic linkIts target location is C:\test\test1But >>> os.path.realpath(r'C:\Users\SAMSUNG\Temp.link\test2')'C:\\Users\\SAMSUNG\\Temp.link\\test2'I thought the return value should be ' C:\\test\\test1\\test2'Is it a bug ? anyone can clear it to me ?-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.realpath(path) bug on win7 ?

2013-01-06 Thread iMath
在 2013年1月6日星期日UTC+8下午3时06分10秒,Chris Rebert写道:
> On Sat, Jan 5, 2013 at 10:55 PM, iMath <[email protected]> wrote:
> 
> >
> 
> > os.path.realpath(path)  bug on win7 ?
> 
> >
> 
> > Temp.link is a Symbolic link
> 
> > Its target location is C:\test\test1
> 
> > But
> 
> > >>> os.path.realpath(r'C:\Users\SAMSUNG\Temp.link\test2')
> 
> > 'C:\\Users\\SAMSUNG\\Temp.link\\test2'
> 
> >
> 
> > I thought the return value should be ' C:\\test\\test1\\test2'
> 
> >
> 
> > Is it a bug ? anyone can clear it to me ?
> 
> 
> 
> What does os.path.islink('C:/Users/SAMSUNG/Temp.link') report?
True
> 
> 
> 
> Cheers,
> 
> Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.realpath(path) bug on win7 ?

2013-01-07 Thread iMath
在 2013年1月7日星期一UTC+8上午7时40分06秒,Victor Stinner写道:
> It looks like the following issue:
> 
> http://bugs.python.org/issue14094
> 
> Victor
> 
> Le 6 janv. 2013 07:59, "iMath" <[email protected]> a écrit :
> 
> 
> 
> 
> os.path.realpath(path)  bug on win7 ?
> 
> Temp.link is a Symbolic link
> Its target location is C:\test\test1
> But 
> >>> os.path.realpath(r'C:\Users\SAMSUNG\Temp.link\test2')
> 'C:\\Users\\SAMSUNG\\Temp.link\\test2'
> 
> 
> I thought the return value should be ' C:\\test\\test1\\test2'
> 
> Is it a bug ? anyone can clear it to me ?
> 
> 
> --
> 
> http://mail.python.org/mailman/listinfo/python-list
perhaps it is
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to detect the character encoding in a web page ?

2013-01-07 Thread iMath
在 2012年12月24日星期一UTC+8上午8时34分47秒,iMath写道:
> how to detect the character encoding  in a web page ?
> 
> such as this page 
> 
> 
> 
> http://python.org/

up to now , maybe chadet is the only way to let python automatically do it .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regular expression : the dollar sign ($) work with re.match() or re.search() ?

2013-01-07 Thread iMath
在 2012年9月26日星期三UTC+8下午3时38分50秒,iMath写道:
> I only know  the dollar sign ($) will match a pattern from the
> 
> end of a string,but which method does it work with ,re.match() or re.search() 
>  ?

I thought re.match('h.$', 'hbxihi') will match ‘hi’ ,but it does not .so why ?
-- 
http://mail.python.org/mailman/listinfo/python-list


what’s the difference between socket.send() and socket.sendall() ?

2013-01-07 Thread iMath
what’s the difference between socket.send() and socket.sendall() ?


It is so hard
for me to tell the difference
between them from the python doc

so what is the difference between them ?

and each one is suitable for which case ?-- 
http://mail.python.org/mailman/listinfo/python-list


How to implement mouse gesture by python or pyqt ?

2013-01-07 Thread iMath
It would be better to give me some examples .thanks in advance !

P.S. which module or lib are needed ?
-- 
http://mail.python.org/mailman/listinfo/python-list


how to download internet files by python ?

2013-01-07 Thread iMath
for example ,if I want to download this file ,how to implement the download 
functionality by python ?

http://down.51voa.com/201208/se-ed-foreign-students-friends-16aug12.mp3

as for  download speed ,of course ,the fast ,the better ,so how to implement it 
?

It would be better to show me an example :) thanks !!!
-- 
http://mail.python.org/mailman/listinfo/python-list


How to get the selected text of the webpage in chrome through python ?

2013-01-07 Thread iMath
How to get the selected text of the webpage in chrome through python ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the selected text of the webpage in chrome through python ?

2013-01-08 Thread iMath
在 2013年1月8日星期二UTC+8下午12时20分28秒,iMath写道:
> How to get the selected text of the webpage in chrome through python ?

I need the code ,cuz  I am only familiar with Python ,so it would be better to 
give me the code written in Python .
You can also give me the code in other programming language   ,thanks in 
advance :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the selected text of the webpage in chrome through python ?

2013-01-08 Thread iMath
在 2013年1月8日星期二UTC+8下午9时19分51秒,Bruno Dupuis写道:
> On Mon, Jan 07, 2013 at 08:20:28PM -0800, iMath wrote:
> 
> > How to get the selected text of the webpage in chrome through python ?
> 
> 
> 
> What you need is a way to get selected text from wherever it comes. The
> 
> way to do this depends on your graphical environment. If you use X, i'd make a
> 
> a quick and dirty call to xclip -o, although there must be a pure python
> 
> implementation which in turn depends on the python framework you play
> 
> with (gtk/qt/wx/tk/...).
> 
> 
> 
> Short answer is : it depends on your system, and it may be easier and more
> 
> portable if you use a graphical toolkit.
> 
> 
> 
> cheers.
> 
> 
> 
> -- 
> 
> Bruno Dupuis

I use it on WinXP , I also learned PyQt4 .
can u help ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the selected text of the webpage in chrome through python ?

2013-01-08 Thread iMath
在 2013年1月8日星期二UTC+8下午9时11分30秒,Dave Angel写道:
> On 01/08/2013 07:38 AM, Dennis Lee Bieber wrote:
> 
> > On Mon, 7 Jan 2013 20:20:28 -0800 (PST), iMath 
> 
> > declaimed the following in gmane.comp.python.general:
> 
> >
> 
> >> How to get the selected text of the webpage in chrome through python ?
> 
> > Chrome is a browser, is it not... If you want to get the text in
> 
> > Python, you have to write the equivalent of a browser -- something that
> 
> > parses the returned HTML message, extracting the parts you want.
> 
> 
> 
> To get a selection, you can either wait till it's copied to the
> 
> clipboard, and get it from there, or you can write a addon for the
> 
> application.  Since Chrome accepts addons, I suggest you research that
> 
> angle.  Probably mozilla.org is the place to start, and function
> 
> 
> 
> nsISelectionController::GetSelection() might be some place to examine.
> 
> 
> 
> You might find some hints in
> 
> http://stackoverflow.com/questions/2671474/range-selection-and-mozilla
> 
> 
> 
> 
> 
> if you are going to work with the clipboard, realize that it works quite
> 
> differently from one OS to another, and even from one desktop manager to
> 
> another.
> 
> 
> 
> -- 
> 
> 
> 
> DaveA

It seems need Javascript to work it on .
Unfortunately ,I am only familiar with python .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to implement mouse gesture by python or pyqt ?

2013-01-08 Thread iMath
在 2013年1月8日星期二UTC+8上午8时44分20秒,iMath写道:
> It would be better to give me some examples .thanks in advance !
> 
> 
> 
> P.S. which module or lib are needed ?

what I wanna perhaps like this:
when a right mouse button is pressed and we go down and right with a cursor. As 
in letter 'L'. Our mouse gesture will close the window.
I googled such gesture examples on PyQt4 ,but hard to find one ,so your help 
will be greatly appreciated !
thanks inadvance !
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the selected text of the webpage in chrome through python ?

2013-01-09 Thread iMath
在 2013年1月9日星期三UTC+8下午5时35分15秒,Alister写道:
> On Mon, 07 Jan 2013 20:20:28 -0800, iMath wrote:
> 
> 
> 
> > How to get the selected text of the webpage in chrome through python ?
> 
> 
> 
> i think you need to explain your  requirement further
> 
> also what do you want to do to the text once you have it?
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Genius is one percent inspiration and ninety-nine percent perspiration.
> 
>   -- Thomas Alva Edison

I want to google it with a mouse gesture
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to download internet files by python ?

2013-01-09 Thread iMath
在 2013年1月8日星期二UTC+8下午1时04分54秒,Roy Smith写道:
> In article ,
> 
>  Cameron Simpson  wrote:
> 
> 
> 
> > On 07Jan2013 20:19, iMath  wrote:
> 
> > | for example ,if I want to download this file ,how to implement the 
> > download 
> 
> > | functionality by python ?
> 
> > | 
> 
> > | http://down.51voa.com/201208/se-ed-foreign-students-friends-16aug12.mp3
> 
> > | 
> 
> > | as for  download speed ,of course ,the fast ,the better ,so how to 
> 
> > | implement it ?
> 
> > | It would be better to show me an example :) thanks !!!
> 
> > 
> 
> > Look at urllib2.
> 
> 
> 
> Even better, look at requests 
> 
> (http://docs.python-requests.org/en/latest/).  There's nothing you can 
> 
> do with requests that you can't do with urllib2, but the interface is a 
> 
> whole lot easier to work with.

There is also a httplib2 module 
https://code.google.com/p/httplib2/

which one is more pythonic and powerful ?
-- 
http://mail.python.org/mailman/listinfo/python-list


How to call wget by python ?

2013-01-09 Thread iMath
can you  give me an example code ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to implement mouse gesture by python or pyqt ?

2013-01-09 Thread iMath
在 2013年1月10日星期四UTC+8上午8时06分13秒,Michael Torrie写道:
> On 01/08/2013 07:57 PM, iMath wrote:
> 
> > 在 2013年1月8日星期二UTC+8上午8时44分20秒,iMath写道:
> 
> >> It would be better to give me some examples .thanks in advance !
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> P.S. which module or lib are needed ?
> 
> > 
> 
> > what I wanna perhaps like this: when a right mouse button is pressed
> 
> > and we go down and right with a cursor. As in letter 'L'. Our mouse
> 
> > gesture will close the window. I googled such gesture examples on
> 
> > PyQt4 ,but hard to find one ,so your help will be greatly appreciated
> 
> > ! thanks inadvance !
> 
> 
> 
> My guess is that if you google for it you'll find a gesture recognition
> 
> module for python.  moosegesture.py is one such implementation.  However
> 
> it is up to you to tie it into your chosen GUI toolkit.  It merely
> 
> processes tuples of points in the gesture.  Each GUI toolkit has mailing
> 
> lists and forums that would help you know that information, which is not
> 
> really python-specific.

oh yes ,I find it  moosegesture.py
-- 
http://mail.python.org/mailman/listinfo/python-list


To make a method or attribute private

2013-01-20 Thread iMath
To make a method or attribute private (inaccessible from the outside), simply 
start its
name with two underscores

《Beginning Python From Novice to Professional》

but there is another saying goes:
Beginning a variable name with a single underscore indicates that the variable 
should be treated as ‘private’.

I test both these 2 rules ,it seems only names that start with two underscores 
are REAL private methods or attributes .

>>> class A:
... def __init__(self):
... self.a = 'a'
... self._a = '_a'
... self.__a = '__a'
...



>>> ap = A()
>>> ap.a
'a'
>>> ap._a
'_a'
>>> ap.__a
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: A instance has no attribute '__a'

so what is your opinion about single leading underscore and private methods or 
attributes?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To make a method or attribute private

2013-01-20 Thread iMath
在 2013年1月17日星期四UTC+8上午9时04分00秒,alex23写道:
> On Jan 17, 10:34 am, "iMath" <[email protected]> wrote:
> 
> > To make a method or attribute private (inaccessible from the outside), 
> > simply start its
> 
> > name with two underscores
> 
> >
> 
> > but there is another saying goes:
> 
> > Beginning a variable name with a single underscore indicates that the 
> > variable should be treated as ‘private’.
> 
> > I test both these 2 rules ,it seems only names that start with two 
> > underscores are REAL private methods or attributes .
> 
> > so what is your opinion about single leading underscore and private methods 
> > or attributes?
> 
> 
> 
> The key word in the second quote is "indicates". Placing a single
> 
> underscore before an attribute name does nothing but _show_ other
> 
> programmers that you consider this to be part of the implementation
> 
> rather than the interface, and that you make no guarantees of its
> 
> continued existence over time.
> 
> 
> 
> More importantly, however: there is no real concept of "private"
> 
> attributes in Python. Try this at the command prompt:
> 
> 
> 
> >>> ap._A__a
> 
> '__a'
> 
> 
> 
> It's still readable, and it's still writable too. The double-
> 
> underscore naming is referred to as "name mangling" and while it's
> 
> often passed off as the way to make private methods in Python (the
> 
> tutorial even states this), what it is really intended for is to
> 
> ensure that multiple inheritance works correctly:
> 
> 
> 
> >>> class A(object):
> 
> ...   foo = 'A'
> 
> ...   def get_A_foo(self):
> 
> ... return self.foo
> 
> ...
> 
> >>> class B(object):
> 
> ...   foo = 'B'
> 
> ...   def get_B_foo(self):
> 
> ... return self.foo
> 
> ...
> 
> >>> class C(A, B):
> 
> ...   def __init__(self):
> 
> ... super(C, self).__init__()
> 
> ...
> 
> >>> c = C()
> 
> >>> c.get_A_foo()
> 
> 'A'
> 
> >>> c.get_B_foo()
> 
> 'A'
> 
> 
> 
> Here, we haven't mangled the attribute 'foo' on either A or B, so on
> 
> the instance of C, which inherits from both, the inherited methods are
> 
> referring to the same attribute, which is A's in this case due to the
> 
> method resolution order. By re-naming 'foo' on both A and B to
> 
> '__foo', each can then refer to their _own_ attribute, and also allow
> 
> for C to have its own 'foo' attribute which doesn't conflict with
> 
> either of them:
> 
> 
> 
> >>> class A(object):
> 
> ...   __foo = 'A'
> 
> ...   def get_A_foo(self):
> 
> ... return self.__foo
> 
> ...
> 
> >>> class B(object):
> 
> ...   __foo = 'B'
> 
> ...   def get_B_foo(self):
> 
> ... return self.__foo
> 
> ...
> 
> >>> class C(A, B):
> 
> ...   foo = 'C'
> 
> ...   def __init__(self):
> 
> ... super(C, self).__init__()
> 
> ...
> 
> >>> c = C()
> 
> >>> c.get_A_foo()
> 
> 'A'
> 
> >>> c.get_B_foo()
> 
> 'B'
> 
> >>> c.foo
> 
> 'C'
> 
> 
> 
> There is no way to make an externally private attribute. This is
> 
> generally considered a good thing by most Python developers: if I
> 
> _need_ to access your class's implementation, I can do so, but the
> 
> name mangling forces me to be aware that this is something you don't
> 
> recommend doing. You'll often hear the term "consenting adults" used
> 
> to refer to this, meaning we can all decide for ourselves if we're
> 
> willing to risk using an implementation detail.

what's the meaning of 'object' in 
class A(object)
and 
class B(object) ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To make a method or attribute private

2013-01-20 Thread iMath
在 2013年1月17日星期四UTC+8上午8时34分22秒,iMath写道:
> To make a method or attribute private (inaccessible from the outside), simply 
> start its 
> name with two underscores
> 
> 
> 《Beginning Python From Novice to Professional》
> 
> 
> but there is another saying goes:
> Beginning a variable name with a single underscore indicates that the 
> variable should be treated as ‘private’.
> 
> 
> I test both these 2 rules ,it seems only names that start with two 
> underscores are REAL private methods or attributes .
> 
> 
> >>> class A:
> ...     def __init__(self):
> ...         self.a = 'a'
> ...         self._a = '_a'
> ...         self.__a = '__a'
> ...
> 
> 
> 
> 
> 
> 
> >>> ap = A()
> >>> ap.a
> 'a'
> >>> ap._a
> '_a'
> >>> ap.__a
> Traceback (most recent call last):
>   File "", line 1, in ?
> AttributeError: A instance has no attribute '__a'
> 
> 
> so what is your opinion about single leading underscore and private methods 
> or attributes?

so there is no REAL private variable in Python but conversion exists in it that 
python programmer should follow and recognize .right ?
-- 
http://mail.python.org/mailman/listinfo/python-list


anyone can make a Python bindings of VLC-Qt ?

2013-01-24 Thread iMath

anyone can make a Python bindings of VLC-Qt  ?
https://github.com/ntadej/vlc-qt
accurately, can anyone make a  PyQt bindings of VLC-Qt  ?
-- 
http://mail.python.org/mailman/listinfo/python-list


what is the difference between commenting and uncommenting the __init__ method in this class?

2013-01-28 Thread iMath
what is the difference between commenting and uncommenting the __init__ method  
in this class?


class CounterList(list):
counter = 0

##def __init__(self, *args):
##super(CounterList, self).__init__(*args)

def __getitem__(self, index):

self.__class__.counter += 1
return super(CounterList, self).__getitem__(index)

-- 
http://mail.python.org/mailman/listinfo/python-list


[os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread iMath
why [os.path.join(r'E:\Python', name) for name in []] returns [] ?
please explain it in detail !
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread iMath
在 2013年1月29日星期二UTC+8下午9时33分26秒,Steven D'Aprano写道:
> iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns 
> [] ? Because you are iterating over an empty list, []. That list 
> comprehension is the equivalent of: result = [] for name in []: 
> result.append( os.path.join(r'E:\Python', name) ) Since you iterate over an 
> empty list, the body of the loop never executes, and the result list remains 
> empty. What did you expect it to do? -- Steven

just in order to get the full path name of each file .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: matplotlib basemap colorbar exception : Given element not contained in the stack

2022-05-29 Thread iMath
please see the formated code at 
https://stackoverflow.com/questions/72423464/matplotlib-basemap-colorbar-exception-given-element-not-contained-in-the-stack
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: matplotlib basemap colorbar exception : Given element not contained in the stack

2022-05-30 Thread iMath
在 2022年5月30日星期一 UTC+8 03:29:28, 写道:
> On 2022-05-29 13:57, iMath wrote: 
> > please see the formated code at 
> > https://stackoverflow.com/questions/72423464/matplotlib-basemap-colorbar-exception-given-element-not-contained-in-the-stack
> The problem might be that you're passing "ax=self.ax" when you create 
> the basemap, and you have: 
> 
> self.ax = self.map_canvas.figure.subplots() 
> 
> According to the docs, ".subplots" doesn't return the axes, it returns a 
> _tuple_ of the figure and the axes.
Thanks for your reply ! But as I printed the value of self.ax , it is actually 
an instance of AxesSubplot.
-- 
https://mail.python.org/mailman/listinfo/python-list


recover pickled data: pickle data was truncated

2021-12-25 Thread iMath
Normally, the shelve data should be read and write by only one process at a 
time, but unfortunately it was simultaneously read and write by two processes, 
thus corrupted it. Is there any way to recover all data in it ? Currently I 
just get "pickle data was truncated" exception after reading a portion of the 
data?

Data and code here 
:https://drive.google.com/file/d/137nJFc1TvOge88EjzhnFX9bXg6vd0RYQ/view?usp=sharing
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: recover pickled data: pickle data was truncated

2021-12-29 Thread iMath
> You have lost the data in that case. 

But I found the size of the file of the shelve data didn't change much, so I 
guess the data are still in it , I just wonder any way to recover my data.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: recover pickled data: pickle data was truncated

2021-12-31 Thread iMath
在 2021年12月30日星期四 UTC+8 03:13:21, 写道:
> On Wed, 29 Dec 2021 at 18:33, iMath  wrote: 
> > But I found the size of the file of the shelve data didn't change much, so 
> > I guess the data are still in it , I just wonder any way to recover my data.
> I agree with Barry, Chris and Avi. IMHO your data is lost. Unpickling 
> it by hand is a harsh work and maybe unreliable. 
> 
> Is there any reason you can't simply add a semaphore to avoid writing 
> at the same time and re-run the code and regenerate the data?

Thanks for your replies! I didn't have a sense of adding a semaphore on writing 
to pickle data before, so  corrupted the data.
Since my data was colleted in the daily usage, so cannot re-run the code and 
regenerate the data.
In order to avoid corrupting my data again and the complicity of using  a 
semaphore, now I am using json text to store my data.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: recover pickled data: pickle data was truncated

2022-01-05 Thread iMath
Thanks for all your kind help, wish you a promising year!
-- 
https://mail.python.org/mailman/listinfo/python-list


use regex to search the page one time to get two types of Information

2016-08-19 Thread iMath
I need to use regex to search two types of Information within a web page, while 
it seems  searching the page two times rather than one is much time consuming , 
is it possible to search the page one time to get two or more types of 
Information?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: use regex to search the page one time to get two types of Information

2016-08-19 Thread iMath
each regex only has one matched result in the web page
-- 
https://mail.python.org/mailman/listinfo/python-list


index for regex.search() beyond which the RE engine will not go.

2016-08-19 Thread iMath

for
regex.search(string[, pos[, endpos]]) 
The optional parameter endpos is the index into the string beyond which the RE 
engine will not go, while this lead me to believe the RE engine will still 
search on till the endpos position even after it returned the matched object, 
is this Right ?

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: use regex to search the page one time to get two types of Information

2016-08-19 Thread iMath
1. searching the page two times rather than one is a little bit time consuming .
2. starting the second search from the first match.endpos does reduce the time 
consuming .
3. how to  combine both patterns into one regex? while using the special | 
regex operator only matches one regex not both 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: use regex to search the page one time to get two types of Information

2016-08-20 Thread iMath
On Friday, August 19, 2016 at 9:19:22 PM UTC+8, Chris Angelico wrote:
> On Fri, Aug 19, 2016 at 11:13 PM, iMath  wrote:
> > 1. searching the page two times rather than one is a little bit time 
> > consuming .
> 
> Have you measured that? If not, ignore it. You're searching a web
> page; if you're downloading that before you search it, chances are
> very good that you spend far more time waiting for the download than
> you ever will on the regex.
> 
> ChrisA

tested,  searching the page two times rather than one is a little bit time 
consuming . 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: use regex to search the page one time to get two types of Information

2016-08-20 Thread iMath
On Friday, August 19, 2016 at 9:45:08 PM UTC+8, Friedrich Rentsch wrote:
> On 08/19/2016 09:02 AM, iMath wrote:
> > I need to use regex to search two types of Information within a web page, 
> > while it seems  searching the page two times rather than one is much time 
> > consuming , is it possible to search the page one time to get two or more 
> > types of Information?
> 
>  >>> r = re.compile ('page|Information|time')
>  >>> r.findall ( (your post) )
> ['Information', 'page', 'page', 'time', 'time', 'page', 'time', 
> 'Information']
> 
> Does that look right?
> 
> Frederic

I found starting the second search from the first match.endpos does reduce the 
time consuming, with less time consuming than your solution ,thanks anyway !
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: index for regex.search() beyond which the RE engine will not go.

2016-08-20 Thread iMath
On Friday, August 19, 2016 at 10:09:19 PM UTC+8, Steve D'Aprano wrote:
> On Fri, 19 Aug 2016 09:14 pm, iMath wrote:
> 
> > 
> > for
> > regex.search(string[, pos[, endpos]])
> > The optional parameter endpos is the index into the string beyond which
> > the RE engine will not go, while this lead me to believe the RE engine
> > will still search on till the endpos position even after it returned the
> > matched object, is this Right ?
> 
> No.
> 
> Once the RE engine finds a match, it stops. You can test this for yourself
> with a small timing test, using the "timeit" module.
> 
> from timeit import Timer
> huge_string = 'aaabc' + 'a'*100 + 'dea'
> re1 = r'ab.a'
> re2 = r'ad.a'
> 
> # set up some code to time.
> setup = 'import re; from __main__ import huge_string, re1, re2'
> t1 = Timer('re.search(re1, huge_string)', setup)
> t2 = Timer('re.search(re2, huge_string)', setup)
> 
> # Now run the timers.
> best = min(t1.repeat(number=1000))/1000
> print("Time to locate regex at the start of huge string:", best)
> best = min(t2.repeat(number=1000))/1000
> print("Time to locate regex at the end of the huge string:", best)
> 
> 
> 
> When I run that on my computer, it prints:
> 
> Time to locate regex at the start of huge string: 4.9710273742675785e-06
> Time to locate regex at the end of the huge string: 0.0038938069343566893
> 
> 
> So it takes about 4.9 microseconds to find the regex at the beginning of the
> string. To find the regex at the end of the string takes about 3893
> microseconds.
> 
> 
> The "endpos" parameter tells the RE engine to stop at that position if the
> regex isn't found before it. It won't go beyond that point.
> 
> 
> 
> 
> 
> 
> -- 
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.

Thanks for clarifying
-- 
https://mail.python.org/mailman/listinfo/python-list


easy way to return a list of absolute file or directory path within a directory

2016-09-07 Thread iMath
Any easier solutions on returning a list of absolute file or directory path 
within a directory? Mine is  

list(map(lambda entry: os.path.join(directory,entry),os.listdir(directory)))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: easy way to return a list of absolute file or directory path within a directory

2016-09-08 Thread iMath
On Wednesday, September 7, 2016 at 4:00:31 PM UTC+8, Steven D'Aprano wrote:
> On Wednesday 07 September 2016 17:08, iMath wrote:
> 
> > Any easier solutions on returning a list of absolute file or directory path
> > within a directory? Mine is
> > 
> > list(map(lambda entry: os.path.join(directory,entry),os.listdir(directory)))
> 
> 
> Use a list comprehension:
> 
> 
> [os.path.join(directory,entry) for entry in os.listdir(directory)]
> 
> 
> 
> -- 
> Steven
> 
> git gets easier once you get the basic idea that branches are homeomorphic 
> endofunctors mapping submanifolds of a Hilbert space.

yes, a  list comprehension does make the code more readable 
-- 
https://mail.python.org/mailman/listinfo/python-list


filesystem encoding 'strict' on Windows

2016-09-29 Thread iMath
the doc of os.fsencode(filename)  says  Encode filename to the filesystem 
encoding 'strict' on Windows, what does 'strict' mean ?
-- 
https://mail.python.org/mailman/listinfo/python-list


python3 - set '\n\n' as the terminator when writing a formatted LogRecord

2016-12-29 Thread iMath
Is it possible to set '\n\n' as the terminator when writing a formatted 
LogRecord to a stream by changing the format parameter of logging.basicConfig?

I know it is possible using the terminator attribute of StreamHandler class to 
implement this, I just wonder Is it possible to achieve this feature by 
changing the format parameter? I am not familiar with the format string language
-- 
https://mail.python.org/mailman/listinfo/python-list


Introducing my Python/PyQt5 powered Bing wallpaper open source project

2017-01-04 Thread iMath
Hello everyone ,
I'd like to introduce my Python/PyQt5 powered Bing wallpaper open source 
project.   
​

BingNiceWallpapers
https://github.com/redstoneleo/BingNiceWallpapers

BingNiceWallpapers can get background images from 
http://www.bing.com/?mkt=zh-CN and set them as your desktop wallpaper by just a 
single click on system tray icon.

For Windows binary installer and more information, please refer to 
http://mathjoy.lofter.com/post/42208d_7cabcf7 (written in simplified Chinese)

Features

Changing wallpaper in a single click on system tray icon or after a specified 
time interval
Windows and Linux Gnome desktop support
Delete or save the current wallpaper


Welcome to help with the project !

-- 
https://mail.python.org/mailman/listinfo/python-list


Introducing my Python/PyQt5 powered Bing wallpaper open source project

2017-01-06 Thread iMath
Hello everyone ,
I'd like to introduce my Python/PyQt5 powered Bing wallpaper open source 
project.
â ï

BingNiceWallpapers
https://github.com/redstoneleo/BingNiceWallpapers

BingNiceWallpapers can get background images from 
http://www.bing.com/?mkt=zh-CN and set them as your desktop wallpaper by just a 
single click on system tray icon.

For Windows binary installer and more information, please refer to 
http://mathjoy.lofter.com/post/42208d_7cabcf7 (written in simplified Chinese)

Features

Changing wallpaper in a single click on system tray icon or after a specified 
time interval
Windows and Linux Gnome desktop support Delete or save the current wallpaper


Welcome to help with the project !

-- 
https://mail.python.org/mailman/listinfo/python-list


send PIL.Image to django server side and get it back

2018-07-16 Thread iMath
I also posted the question here
https://stackoverflow.com/questions/51355926/send-pil-image-to-django-server-side-and-get-it-back

I don't know what's under the hood of sending an image from client side to 
server side, so stuck by the following scenario.

I want to send a PIL.Image object to django server side using the Python 
requests lib and get it back in order to use the PIL.Image object on server 
side. As I have tested , if sent the PIL.Image object without any conversion , 
that is

r = requests.post(SERVER_URL,
data={
'image': PILimage,#PILimage is of type PIL.Image
'wordPos':(86,23)
},
)
then I just got a str object with value   on server side, I guess it was caused by  
requests, which converted the PIL.Image object to a str object before sending, 
so why  requestsdo the conversion ? why cannot we send the PIL.Image object 
without any conversion over the Internet ? please give some explanation here, 
thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: send PIL.Image to django server side and get it back

2018-07-22 Thread iMath
Thanks, I solved it finally stackoverflow.com/a/51453785/1485853
-- 
https://mail.python.org/mailman/listinfo/python-list


right way to use zipimport, zipimport.ZipImportError: not a Zip file

2018-08-13 Thread iMath
The same question also posted here
https://stackoverflow.com/questions/51820473/right-way-to-use-zipimport-zipimport-zipimporterror-not-a-zip-file

I have managed to use [this module][1] without installation - just import it 
from path to use , 

import sys
url = 'https://example.com'
sys.path.insert(0, r'C:\Users\i\Downloads\you-get-0.4.1128\src')  # 
from you_get import common
common.any_download(url, info_only=True)#NoneType

It seems possible in Python to use `zipimport` to directly use the zip archive 
of the module without extraction, I wonder what is the right way to use 
`zipimport`, a simple trying like the following just gives the exception . I 
downloaded the file from [here][2] , the file 
`C:\Users\i\Downloads\you-get-0.4.1128.zip` does exist and isn't corrupted.

>>> import zipimport
>>> zipimport.zipimporter(r'C:\Users\i\Downloads\you-get-0.4.1128.zip')
Traceback (most recent call last):
  File "", line 1, in 
zipimport.zipimporter(r'C:\Users\i\Downloads\you-get-0.4.1128.zip')
zipimport.ZipImportError: not a Zip file: 
'C:\\Users\\i\\Downloads\\you-get-0.4.1128.zip'
>>> 


  [1]: https://github.com/soimort/you-get/releases
  [2]: https://github.com/soimort/you-get/archive/v0.4.1128.zip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: right way to use zipimport, zipimport.ZipImportError: not a Zip file

2018-08-14 Thread iMath
I think someone gives the true reason caused the exception here
https://stackoverflow.com/a/51821910/1485853

Thanks to his  explanation , I extracted the zip archive and then add the 
extracted to a zip archive using Bandizip, this time 
`zipimport.zipimporter(r'C:\Users\i\Downloads\you-get-0.4.1128.zip') ` doesn't 
give the exception , but still cannot import the module, even adding the  
`.zip`  file to  `sys.path`,

>>> import sys
>>> sys.path.insert(0, 
r'C:\Users\i\Downloads\you-get-0.4.1128.zip\you-get-0.4.1128\src')
>>> from you_get import common
Traceback (most recent call last):
  File "", line 1, in 
from you_get import common
ModuleNotFoundError: No module named 'you_get'
>>> 


>>> import zipimport
>>> 
z=zipimport.zipimporter(r'C:\Users\i\Downloads\you-get-0.4.1128.zip\you-get-0.4.1128\src')
>>> z

>>> z.load_module('you_get.common')
Traceback (most recent call last):
  File "", line 1, in 
z.load_module('you_get.common')
zipimport.ZipImportError: can't find module 'you_get.common'
>>> z.load_module('you_get')
Traceback (most recent call last):
  File "", line 1, in 
z.load_module('you_get')
zipimport.ZipImportError: can't find module 'you_get'


What I actually want to do is to use the module in  a pyinstaller frozen 
application  , I also need to upgrade  the module  to latest version whenever 
needed , I cannot find a solution yet.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: right way to use zipimport, zipimport.ZipImportError: not a Zip file

2018-08-14 Thread iMath
I think someone gives the true reason caused the exception here
https://stackoverflow.com/a/51821910/1485853

Thanks to his  explanation , I extracted the zip archive and then add the 
extracted to a zip archive using Bandizip, this time 
`zipimport.zipimporter(r'C:\Users\i\Downloads\you-get-0.4.1128.zip') ` doesn't 
give the exception , but still cannot import the module, even adding the  
`.zip`  file to  `sys.path`,

>>> import sys
>>> sys.path.insert(0, 
r'C:\Users\i\Downloads\you-get-0.4.1128.zip\you-get-0.4.1128\src')
>>> from you_get import common
Traceback (most recent call last):
  File "", line 1, in 
from you_get import common
ModuleNotFoundError: No module named 'you_get'
>>> 


>>> import zipimport
>>> 
z=zipimport.zipimporter(r'C:\Users\i\Downloads\you-get-0.4.1128.zip\you-get-0.4.1128\src')
>>> z

>>> z.load_module('you_get.common')
Traceback (most recent call last):
  File "", line 1, in 
z.load_module('you_get.common')
zipimport.ZipImportError: can't find module 'you_get.common'
>>> z.load_module('you_get')
Traceback (most recent call last):
  File "", line 1, in 
z.load_module('you_get')
zipimport.ZipImportError: can't find module 'you_get'


What I actually want to do is to use the module in  a pyinstaller frozen 
application  , I also need to upgrade  the module  to latest version whenever 
needed , I cannot find a solution yet.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: right way to use zipimport, zipimport.ZipImportError: not a Zip file

2018-08-15 Thread iMath
Not works on Windows 

>>> import sys
>>> sys.path.insert(0, 
>>> 'C:/Users/i/Downloads/you-get-0.4.1128.zip/you-get-0.4.1128/src')
  
>>> from you_get import common
  
Traceback (most recent call last):
  File "", line 1, in 
from you_get import common
ModuleNotFoundError: No module named 'you_get'
>>> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Design an encrypted time-limited API on Client/Server side

2016-06-08 Thread iMath
​I am planning design an encrypted time-limited API on both Client and Server 
sides, the server side is written in Django, the client side is a GUI program 
which call the API by
import requests
c = requests.post("http://127.0.0.1:8000/VideoParser/";, data={'videoUrl': 
videoUrl })
The way it call the API is desperately exposed to those who can use network 
traffic capturing tools like wireshark and fiddler, while I don't want anyone 
else could call the API with their customized videoUrl, and if people made the 
post call with the same parameters 2 minutes later after the client initially 
made the call, the call should be valid or expired, so how to design the 
encrypted time-limited API on both Client and Server side in this case ?

P.S. I think add an identifier to the post data could prevent them using the API

import requests
c = requests.post("http://127.0.0.1:8000/VideoParser/";, data={'videoUrl': 
videoUrl, 'identifier':value_of_identifier })
provided there is something encrypted in the value_of_identifier and it changes 
with each call, but I don't know how to get started, any idea ?

It would be better to show some code , I really don't know which modules to use 
and  how to start to write code.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Win32 API in pywin32

2016-08-04 Thread iMath
On Friday, August 5, 2016 at 7:50:28 AM UTC+8, [email protected] wrote:
> According to Python.org Mark Hammond has an Add-on (pywin32) that supports 
> Win32 and COM.
> 
> Does anyone know if the Add-on covers all Win32 API functions, and if not is 
> there a list of the subset of Win32 API functions it does include?
> 
> J.

According to my experience , pywin32 doesn't  covers all Win32 API functions 
but most of them , so for these not supported functions, you could resort to 
ctypes
,and  there seems no list of the subset of Win32 API functions it does include.

You can contact with the developers of pywin32 using the mailing list  
[email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


get a certain request url during Loading a web page

2016-08-04 Thread iMath
During Loading this web page(http://www.iqiyi.com/v_19rrkkri8k.html) , the 
browser makes many requests,now I need a certain request url (e.g.starts with 
'http://cache.video.qiyi.com/vms?') during the Loading process ,and the request 
is made on condition that the adobe flash player plugin for NPAPI is enabled , 
so any way to get the url via python ?

P.S. Better to show some code, I am new to this area.
-- 
https://mail.python.org/mailman/listinfo/python-list


find all js/css/image pathnames in a HTML document

2019-05-11 Thread iMath
To find all js/css/image pathnames in a HTML document, I used regular 
expression(in the last line of my code snippet) to do this as the following, 
are there any other shorter regular expressions or more efficient ways to do 
this ?


import re
translation='''



  



  bee·tle™

  

/

ˈbiːtl



;

  NAmE



ˈbiːtl



/

  

  



  noun



,



  verb



  





  beetle

  beetles

  beetled

  beetling



  

  

  



  

noun

  

  

  

  





  1

  

an insect, often 
large and black, with a hard case on its back, covering its wings. There are 
several types of

  beetle.

  甲虫



  

  

☞see also



  



  death-watch beetle



  



  





  2

  Beetle

  

(



  NAmE also



bug

)

  

  

the English names 
for the original Volkswagen small car with a round shape at the front and the 
back

  “甲壳虫”(英国人用以指称一款圆头圆顶的原大众牌的小汽车)



  



  

  

  



  

verb

  





  [intransitive

  ]



+ 
adv./prep.



  (

BrE) (

informal)

  

  to move somewhere 
quickly

快速移动

  





  SYN

  



  

scurry

  



  





  ◆

  I last saw 
him beetling off down the road.

  我上次见到他时,他正快步沿路而去。



  

  



  bee·tle™

  

/

ˈbiːtl



;

  NAmE



ˈbiːtl



/

  



  


'''
print(re.findall(r'(?:href|src)="([^"]+?\.(?:css|js|png|jpg))"', translation))
-- 
https://mail.python.org/mailman/listinfo/python-list


celery multi celery.exceptions.TimeoutError: The operation timed out

2020-09-18 Thread iMath
I followed the official [Celery 
guide](https://docs.celeryproject.org/en/stable/getting-started/next-steps.html#in-the-background)
 to learn, everything works well when using `celery -A proj worker -l info` to  
start the worker, however , if I run the worker in the background using `celery 
multi restart w1 -A proj -l info --logfile=./celery.log`, then I got 


>>> from proj.tasks import add
>>> add.delay().get(timeout=19)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python3.8/dist-packages/celery/result.py", line 230, 
in get
return self.backend.wait_for_pending(
  File "/usr/local/lib/python3.8/dist-packages/celery/backends/base.py", 
line 660, in wait_for_pending
meta = self.wait_for(
  File "/usr/local/lib/python3.8/dist-packages/celery/backends/base.py", 
line 696, in wait_for
raise TimeoutError('The operation timed out.')
celery.exceptions.TimeoutError: The operation timed out.
>>>
So what's wrong ?

Test environment :

 - Python 3.8.2 
 - celery multi v4.4.7
 - rabbitmqctl version --->3.8.2

and Project layout ([code 
files](https://github.com/celery/celery/files/5231502/proj.zip)):

> proj/__init__.py
> /celery.py
> /tasks.py

celery.py

from __future__ import absolute_import, unicode_literals

from celery import Celery

app = Celery('proj',
 broker='amqp://localhost',
 # backend='db+sqlite:///results.sqlite',  # The backend 
argument, If you don’t need results, it’s better to disable them.  Results can 
also be disabled for individual tasks by setting the @task(ignore_result=True) 
option.
 include=['proj.tasks'])  # The include argument is a list of 
modules to import when the worker starts. You need to add our tasks module here 
so that the worker is able to find our tasks.
app.conf.CELERY_RESULT_BACKEND = 'db+sqlite:///results.sqlite'

if __name__ == '__main__':
app.start()

tasks.py

from __future__ import absolute_import, unicode_literals
from .celery import app
import datetime
@app.task
def add():
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")


The log info as the following , I googled , but didn't find a working solutions 
```
[2020-09-15 22:10:03,229: INFO/MainProcess] Connected to 
amqp://guest:**@127.0.0.1:5672//
[2020-09-15 22:10:03,238: INFO/MainProcess] mingle: searching for neighbors
[2020-09-15 22:10:04,260: INFO/MainProcess] mingle: all alone
[2020-09-15 22:10:04,273: INFO/MainProcess] w1@iZwz962a07bhoio77q4ewxZ ready.
[2020-09-15 22:10:10,625: ERROR/MainProcess] Received unregistered task of type 
'proj.tasks.add'.
The message has been ignored and discarded.

Did you remember to import the module containing this task?
Or maybe you're using relative imports?

Please see
http://docs.celeryq.org/en/latest/internals/protocol.html
for more information.

The full contents of the message body was:
'[[], {}, {"callbacks": null, "errbacks": null, "chain": null, "chord": null}]' 
(77b)
Traceback (most recent call last):
  File 
"/usr/local/lib/python3.8/dist-packages/celery/worker/consumer/consumer.py", 
line 562, in on_task_received
strategy = strategies[type_]
KeyError: 'proj.tasks.add'

```
-- 
https://mail.python.org/mailman/listinfo/python-list


celery multi celery.exceptions.TimeoutError: The operation timed out

2020-09-21 Thread iMath
Asked 3 days ago at 
https://stackoverflow.com/questions/63951696/celery-multi-celery-exceptions-timeouterror-the-operation-timed-out

But nobody helped yet, anyone ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: celery multi celery.exceptions.TimeoutError: The operation timed out

2020-09-26 Thread iMath
在 2020年9月21日星期一 UTC+8 下午8:02:44, 写道:
> Op 21-09-2020 om 12:14 schreef iMath:
> > Asked 3 days ago at 
> > https://stackoverflow.com/questions/63951696/celery-multi-celery-exceptions-timeouterror-the-operation-timed-out
> >  
> > 
> > But nobody helped yet, anyone ? 
> >
> Did you see 
> https://stackoverflow.com/questions/9769496/celery-received-unregistered-task-of-type-run-example
>  
> ? 
> 
> The error says "Received unregistered task of type 'proj.tasks.add'", so 
> it looks very much like your registry is not correct/complete. 
> 
> Vriendelijke groeten/Kind regards, 
> 
> Menno Hölscher

None of the answers helped .
Finally ,I switched to https://github.com/jarekwg/django-apscheduler I found it 
is elegant and easy to use
-- 
https://mail.python.org/mailman/listinfo/python-list


run command line on Windows without showing DOS console window

2013-11-20 Thread iMath


is there anyway to run command line on Windows without showing DOS console 
window ?

can you use the following command line to give a little example ?

wget -r -np -nd http://example.com/packages/

the path to wget is C:\Program Files\GnuWin32\bin\wget.exe
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: run command line on Windows without showing DOS console window

2013-11-23 Thread iMath
在 2013年11月20日星期三UTC+8下午10时49分50秒,Tim Golden写道:
> On 20/11/2013 14:44, iMath wrote:
> 
> > 
> 
> > 
> 
> > is there anyway to run command line on Windows without showing DOS console 
> > window ?
> 
> > 
> 
> > can you use the following command line to give a little example ?
> 
> > 
> 
> > wget -r -np -nd http://example.com/packages/
> 
> > 
> 
> > the path to wget is C:\Program Files\GnuWin32\bin\wget.exe
> 
> > 
> 
> 
> 
> subprocess.call(["wget", "-r", "-np", "-nd", "http://example.com";])
> 
> 
> 
> TJG
Have you tried it ? the DOS console window still pops up?
but I found when shell=True ,the DOS console window doesn't pop up,anyone can 
explain why ?
-- 
https://mail.python.org/mailman/listinfo/python-list


how to implement a queue-like container with sort function

2013-11-28 Thread iMath
I want to a fixed length list-like container, it should have a sorted()-like 
function that I can use to sort it,I think there should also a function I can 
use it to detect whether the numbers of items in it reaches the length of the 
container , because if the numbers of items in it reaches the length(fixed) of 
the container,I want to process the data in it .Is there a container in Python 
like this ?If not, what base container should be used to implement such 
container?

the container is similar to queue ,but queue doesn't have a sort  function 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to implement a queue-like container with sort function

2013-11-28 Thread iMath
All in all,I want to first fill the container, then sort it and process all the 
contents in it 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to implement a queue-like container with sort function

2013-11-28 Thread iMath
hey , you used
>>> sorted(a.queue)

this means the queue.Queue() has an attribute queue ,but I cannot find it 
described in the DOC ,where you find it ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to implement a queue-like container with sort function

2013-11-29 Thread iMath
it seems  PriorityQueue satisfy my requirement here .

BTW ,the Queue object has an attribute 'queue' ,but I cannot find it described 
in the DOC ,what it means ?
-- 
https://mail.python.org/mailman/listinfo/python-list


using ffmpeg command line with python's subprocess module

2013-12-02 Thread iMath
I have few wav files that I can use either of the following command line 
mentioned here
https://trac.ffmpeg.org/wiki/How%20to%20concatenate%20%28join,%20merge%29%20media%20files
 to concatenate


ffmpeg -f concat -i <(for f in ./*.wav; do echo "file '$f'"; done) -c copy 
output.wav
ffmpeg -f concat -i <(printf "file '%s'\n" ./*.wav) -c copy output.wav
ffmpeg -f concat -i <(find . -name '*.wav' -printf "file '%p'\n") -c copy 
output.wav


anyone know how to convert either of them to work with python's subprocess 
module, it would be better if your solution is platform independent .
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   >