helping with unicode
it's a simple source view program.
the codec of the target website is utf-8
so I read it and print the decoded
--
#-*-coding:utf8-*-
import urllib2
rf=urllib2.urlopen(r"http://gall.dcinside.com/list.php?id=programming";)
print rf.read().decode('utf-8')
raw_input()
---
It works fine on python shell
but when I make the file "wrong.py" and run it,
Error rises.
Traceback (most recent call last):
File "C:wrong.py", line 8, in
print rf.read().decode('utf-8')
UnicodeEncodeError: 'cp949' codec can't encode character u'u1368' in position 5
5122: illegal multibyte sequence
-
cp949 is the basic codec of sys.stdout and cmd.exe
but I have no idea why it doesn't works.
printing without decode('utf-8') works fine on IDLE but on cmd, it print broken
characters(Ascii portion is still fine, problem is only about the Korean)
the question may look silly:(
but I want to know what is the problem or how to print the not broken strings.
thanks for reading.
--
http://mail.python.org/mailman/listinfo/python-list
how to interact with Windows cmd?
what I want to do is
1.open cmd
2.waiting for user's typing
3.when I type "dir"
4.print the result of "dir"
5.then I type some other commands, printing the result until I type
'exit'
I used
p=subprocess.Popen('cmd',stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
p=communicate('dir')
it shows the first result but the problem is
1. it's too long so the cmd split the result with "more?", so result
is not perfect
2. after this, I typed like "cd .." but I/O is already closed so I
can't do another things..
Is there any good way?
--
http://mail.python.org/mailman/listinfo/python-list
why greenlet, gevent or the stackless are needed?
(I'm very new to this coroutine part so It's not supposed to attack these modules, just I don't know the differences) atfer version 2.5, python officially support coroutine with yield. and then, why greenlet, gevent, Stackless python are still useful? it there somthing that "yield" can't do or just it is easier or powerful? -- http://mail.python.org/mailman/listinfo/python-list
Re: why greenlet, gevent or the stackless are needed?
r 2012년 7월 7일 토요일 오후 4시 33분 26초 UTC+9, Devin Jeanpierre 님의 말: > On Sat, Jul 7, 2012 at 3:09 AM, self.python wrote: > > it there somthing that "yield" can't do > > or just it is easier or powerful? > > couroutine-like generators can't give up control flow unless they are > the top level function handled by the coroutine controller thing. For > example, we can do this: > > def foo(): > while True: > next_value = (yield) > print next_value > > But we can't do this: > > def yap(): > next_value = (yield) > print next_value > > def foo(): > while True: > yap() > > If we explicitly say that "yap" can control us, via "yield from" (new > in Python 3.3), then we can do something like the above, but this > still requires explicit markup. In all other releases of Python, this > is impossible. > > On the other hand, coroutines in greenlet et al can do a coroutine > context switch at any point. The upside is that this is more flexible > (and does something generators pre-3.3 cannot). The downside is that > you now need locking structures to guarantee atomic interactions with > a shared resource, whereas with generators you know that you always > are the sole thing running, until you do a yield (and unless real > threads or greenlet or whatever are involved, of course.) > > -- Devin first, thanks for good answer:) but I don't understand why the code def yap(): next_value = (yield) print next_value def foo(): while True: yap() really do. what is the purpose of that code? -- http://mail.python.org/mailman/listinfo/python-list
how can I make it work?
it's a finder using threading to accelerate but it never works..
and I have no idea why it doesn't work:(
it doesn't work too after changing threading to multiprocessing..
how can I make it work? or at least I know what's the problem...
plz help the poor newbie...
import os,threading,multiprocessing
def finder(path,q):
for x in os.walk(unicode(path)):
if x[1]:
for dirname in x[1]:
if target in dirname.lower():
q.put(os.path.join(x[0],dirname))
if x[2]:
for name in x[2]:
if target in name.lower():
q.put(os.path.join(x[0],name))
q.put(1)
def printer(q):
cmd=0
while 1:
tmp=q.get()
if tmp==1:
cmd += 1
continue
if cmd ==thnum:
break
print tmp
if __name__ =="__main__":
q=multiprocessing.JoinableQueue()
ini=os.walk(u"C:\\").next()
thnum=len(ini[1])
target=raw_input("what you wanna get\n")
p=multiprocessing.Process(target=printer,args=(q,))
p.daemon=1
p.start()
for i in xrange(thnum):
t=threading.Thread(target=finder,args=(ini[1][i],q,))
t.start()
print i," started"
q.join()
--
http://mail.python.org/mailman/listinfo/python-list
Re: how can I make it work?
2012년 7월 9일 월요일 오전 11시 2분 41초 UTC+9, self.python 님의 말:
> it's a finder using threading to accelerate but it never works..
> and I have no idea why it doesn't work:(
> it doesn't work too after changing threading to multiprocessing..
> how can I make it work? or at least I know what's the problem...
> plz help the poor newbie...
>
>
>
> import os,threading,multiprocessing
>
>
> def finder(path,q):
> for x in os.walk(unicode(path)):
> if x[1]:
>for dirname in x[1]:
> if target in dirname.lower():
> q.put(os.path.join(x[0],dirname))
> if x[2]:
>for name in x[2]:
> if target in name.lower():
> q.put(os.path.join(x[0],name))
>
> q.put(1)
>
> def printer(q):
> cmd=0
> while 1:
> tmp=q.get()
> if tmp==1:
>cmd += 1
>continue
> if cmd ==thnum:
>break
> print tmp
>
> if __name__ =="__main__":
> q=multiprocessing.JoinableQueue()
> ini=os.walk(u"C:\\").next()
> thnum=len(ini[1])
> target=raw_input("what you wanna get\n")
>
> p=multiprocessing.Process(target=printer,args=(q,))
> p.daemon=1
> p.start()
>
> for i in xrange(thnum):
> t=threading.Thread(target=finder,args=(ini[1][i],q,))
> t.start()
> print i," started"
> q.join()
It shows
0 started
1 started
...
22 started
but then it show nothing
the cursur blinks continuously
but the result never printed(maybe not produces?)
--
http://mail.python.org/mailman/listinfo/python-list
Re: how can I make it work?
2012년 7월 9일 월요일 오전 11시 41분 32초 UTC+9, self.python 님의 말:
> 2012년 7월 9일 월요일 오전 11시 2분 41초 UTC+9, self.python 님의 말:
> > it's a finder using threading to accelerate but it never works..
> > and I have no idea why it doesn't work:(
> > it doesn't work too after changing threading to multiprocessing..
> > how can I make it work? or at least I know what's the problem...
> > plz help the poor newbie...
> >
> >
> >
> > import os,threading,multiprocessing
> >
> >
> > def finder(path,q):
> > for x in os.walk(unicode(path)):
> > if x[1]:
> >for dirname in x[1]:
> > if target in dirname.lower():
> > q.put(os.path.join(x[0],dirname))
> > if x[2]:
> >for name in x[2]:
> > if target in name.lower():
> > q.put(os.path.join(x[0],name))
> >
> > q.put(1)
> >
> > def printer(q):
> > cmd=0
> > while 1:
> > tmp=q.get()
> > if tmp==1:
> >cmd += 1
> >continue
> > if cmd ==thnum:
> >break
> > print tmp
> >
> > if __name__ =="__main__":
> > q=multiprocessing.JoinableQueue()
> > ini=os.walk(u"C:\\").next()
> > thnum=len(ini[1])
> > target=raw_input("what you wanna get\n")
> >
> > p=multiprocessing.Process(target=printer,args=(q,))
> > p.daemon=1
> > p.start()
> >
> > for i in xrange(thnum):
> > t=threading.Thread(target=finder,args=(ini[1][i],q,))
> > t.start()
> > print i," started"
> > q.join()
>
>
> It shows
> 0 started
> 1 started
> ...
> 22 started
> but then it show nothing
> the cursur blinks continuously
> but the result never printed(maybe not produces?)
I knew what's the problem on other site.
It just because I miss to send the full path to each thread...
what an idiot..
but I'm still wondering that there is any good way
--
http://mail.python.org/mailman/listinfo/python-list
