Re: [Tutor] Good Text Editor/IDE for Python
On Sun, Aug 31, 2014 at 7:12 PM, Juan Christian wrote: > I've been using PyCharm to code in Python but it seems a bit "overpowered" > for this task, and there are some annoying bugs. I used Sublime Text 2 in > the past, but it seems to be dead now (last update was JUN/2013), so I don't > really know any good options. > Sublime Text is still being developed by its creator. He is just being slow (thorough?) about it. A seemingly stable beta version of Sublime Text 3 is available, and the plugin community is actively developing for it. boB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Good Text Editor/IDE for Python
On Monday, September 01, 2014 08:12 AM, Juan Christian wrote: > I've been using PyCharm to code in Python but it seems a bit > "overpowered" for this task, and there are some annoying bugs. I used > Sublime Text 2 in the past, but it seems to be dead now (last update > was JUN/2013), so I don't really know any good options. > > What do you guys use to code? > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor my favourite is githubs Atom https://atom.io/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Good Text Editor/IDE for Python
Sorry Peter, but you message is blank here. I (and presumedly the others) can't read a thing. On Monday, September 1, 2014, Peter Romfeld wrote: > On Monday, September 01, 2014 08:12 AM, Juan Christian wrote: > > I've been using PyCharm to code in Python but it seems a bit "overpowered" > for this task, and there are some annoying bugs. I used Sublime Text 2 in > the past, but it seems to be dead now (last update was JUN/2013), so I > don't really know any good options. > > What do you guys use to code? > > > ___ > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription > options:https://mail.python.org/mailman/listinfo/tutor > > my favourite is githubs Atom > https://atom.io/ > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Good Text Editor/IDE for Python
On Mon, Sep 01, 2014 at 09:14:15AM -0300, Juan Christian wrote: > Sorry Peter, but you message is blank here. I (and presumedly the others) > can't read a thing. Peter's message is tucked away at the very end of the quoted text, after the footer, with no blank line separating it from the quotes. It took me two goes to notice it too: > > my favourite is githubs Atom > > https://atom.io/ -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Good Text Editor/IDE for Python
On Sunday, 31 Aug 2014 21:12, Juan Christian wrote: > I've been using PyCharm to code in Python but it seems a bit "overpowered" > for this task, and there are some annoying bugs. > What do you guys use to code? While I haven't really noticed any big bugs in PyCharm apart from the dog-slow debugger which really annoys me (anyone got suggestions how to speed it up?), I also regularly jump into (g)vim for most smaller tasks. Pycharm is also setup with the IdeaVim Plugin so my keymaps match and I don't mess up my muscle-memory. In vim I use some plugins for my development work, most notably YouCompleteMe, Unity, Fugitive+gitgutter, Syntastic and Ultisnips. Oh, ctags are also great to have. So it's basically about the task at hand - if it's some bigger project at work and/or home I want to play with, I usually fire up PyCharm and it's well worth it. For me the overhead is negligible - especially so if you put some Javascript/Jinja/etc/etc into the mix. Jetbrain's plugins and integration for almost anything under the sun are just amazing. For everything else it's vim I use. -- Best regards, /Gordon Schulz @azmd ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how import a module upon instantiation of a class?
- Original Message - > From: Peter Otten <__pete...@web.de> > To: tutor@python.org > Cc: > Sent: Monday, September 1, 2014 1:17 AM > Subject: Re: [Tutor] how import a module upon instantiation of a class? > > Albert-Jan Roskam wrote: > >> I want to import a module upon instantiation (not definition) of a class. >> What is the best way to do this? In my case, I need the "icu" > module in >> only one place/class of the program. If that class won't be used, I > don't >> want to have an ImportError. Also, it might be nice to do the imports only >> when you actually need that functionality. It's probably not really >> PEP-compliant to put the imports somewhere else than at the top of the >> module, but I can live with that. >> >> >> import some_nonbuiltin # I don't want it here! >> >> >> class KlassA(object): >> import some_nonbuiltin # nope >> >> def __init__(self): > global some_nonbuiltin > import some_nonbuiltin Ahh with 'global', thank you! It never crossed my mind that this should be used in this case. Within functions, 'global' is only required when the global variable is going to be modified. Given that the module won't be changed, why is global required? Regards, Albert-Jan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] abc module question
Hi, I was playing with abc for the first time (never ever had any use for it). It works nicely with methods and properties. But is there also a way to enforce that class Concrete has an attribute 'foo' of type 'list'? I could of course write a 'foo' property, but I was hoping there was a direct way, import sys import abc class Abstract(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod def __init__(self): pass @abc.abstractmethod def __getitem__(self, key): raise NotImplementedError("__getitem__ method required!") @abc.abstractproperty def encoding(self): raise NotImplementedError("encoding property required!") @abc.abstractproperty def foo(self): assert isinstance(self.foo, list) class Concrete(Abstract): def __init__(self): self.foo = [] # it could be solved by making foo a property def __getitem__(self, key): pass @property def encoding(self): return "some encoding" c = Concrete() Traceback (most recent call last): File "C:\TEMP\abc_foo.py", line 46, in c = Concrete() TypeError: Can't instantiate abstract class Concrete with abstract methods foo Regards, Albert-Jan PS: Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Good Text Editor/IDE for Python
On Mon, Sep 01, 2014 at 11:57:08AM +1000, Cameron Simpson wrote: > On 01Sep2014 11:13, Steven D'Aprano wrote: > >Just recently, I've customised my interactive Python with a powerful set > >of tab completion commands, similar to that provided by IPython. While > >typing, if I hit tab, it will try to complete the current variable, > >function, module or file name. I don't know how I programmed without it > >all these years :-) > > I must try that sometime. Please do :-) You can get the module from here: http://code.google.com/p/tabhistory/ Or directly using Mercurial. Run this command at the shell: hg clone https://code.google.com/p/tabhistory/ For experts: you can work out what to do next :-) It's a single .py file and it has lots of documentation. For beginners: once you have run the hg comand above, copy the file tabhistory/tabhistory.py somewhere where Python will see it. Then, start the Python interactive interpreter, and run: import tabhistory If that succeeds, it is now running! If it does not, please let me know what errors you get. I am especially interested in the experience of Mac and Windows users. (Windows users: you will need the third-party pyreadline module.) Try it out: at the interactive interpreter, type: imp[TAB] where [TAB] means "press the TAB key". Python should complete the command line and give you "import". Continue to type: import co[TAB][TAB] and Python will print the names of all modules beginning with "co" that it can see. On my system, that is: code codeop colorsys compileall contextlib copy codecs collections commands compiler cookielibcopy_reg Keep typing: import coll[TAB] and Python will complete the command to: import collections Additional features: - If you press TAB at the beginning of a line, it will insert an actual tab character. That can be configured if you prefer spaces. - Inside quoted strings, it will complete on file names. - After something like "from module import " pressing TAB will complete on the attributes of module, but only if module has already been imported and is in the sys.modules cache. This is a security feature. - As the name hints at, tabhistory also enables command history. Press the up-arrow repeatedly to call up previous commands, and down-arrow to move forward through the history again. tabhistory also creates two objects for customizing the completion and history functions: from tabhistory import history, completer will let you conveniently work with them. Both are extensively documented. One particularly useful feature: calling the history object history() will display the last 10 (by default) lines in the history. (Question: anyone know how to tell readline to jump straight to a particular history line? M-< goes to the oldest line in the history, and M-> goes to the most recent, but how would I go straight to line 87?) Feedback, suggestions and bug reports will be gratefully accepted. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how import a module upon instantiation of a class?
On Mon, Sep 01, 2014 at 06:46:41AM -0700, Albert-Jan Roskam wrote: > >> def __init__(self): > > global some_nonbuiltin > > import some_nonbuiltin > > Ahh with 'global', thank you! It never crossed my mind that this > should be used in this case. Within functions, 'global' is only > required when the global variable is going to be modified. No! Absolutely not! The "global" keyword is needed when the global *name* is going to be re-bound to a different object, it has nothing to do with modifying objects. Let's see how we might "modify a variable": py> mylist = [] py> def spam(): ... mylist.append(42) # modifies the mylist object ... py> spam() py> spam() py> print mylist [42, 42] Calling spam() doesn't change what the name "mylist" refers to, it's still the same list, but the list does get changed. If you re-bind the name, by default Python treats it as a local variable: py> def eggs(): ... mylist = ["something", "else"] ... py> eggs() py> print mylist [42, 42] You need the global keyword to make eggs() consider "mylist" to be global rather than local: py> def eggs(): # take two ... global mylist ... mylist = ["something", "else"] ... py> eggs() py> print mylist ['something', 'else'] The import statement performs a name binding: it creates a variable with the same name as the module (or the name given by "as"). py> math # name doesn't exist yet Traceback (most recent call last): File "", line 1, in NameError: name 'math' is not defined py> import math py> math # now the name exists, same as if we said "math = ..." So what happens if you put an import inside a function? It creates a variable with the name of the module. Since it is inside a function, it is a *local* variable, which makes it invisible to anything outside of that module: py> def cheese(): ... import string ... py> cheese() py> string Traceback (most recent call last): File "", line 1, in NameError: name 'string' is not defined To make it a global name, you need the global keyword: py> def cheese(): # take two ... global string ... import string ... py> cheese() py> string -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] python pipeline
Dear all, I'll try to write a pipeline starting from a csv file where I write the name and the path of my files. example.csv Name,FASTQ1,FASTQ2,DIRECTORY sampleA,A_R1_.fastq.gz,A_R2_.fastq.gz,108,~/FASTQ/ sampleB,B_R1_.fastq.gz,B_R2_.fastq.gz,112,~/FASTQ/ On that list I need to send each time 3 different script whic are depend one to the other. So I need to run1 and only whe it finisched start the second and then the 3. One of the problems teach script write the output only in the same directory where I launch the program so I need to create. I set the output directory and the I want to obtain this folder view . ├── sampleA │ ├── ref.txt │ └── second └── sampleB ├── ref.txt └── second I have problems on how to move in different folder and how can use subprocess for execute all. Any idea in how can I do this? def Staralign(file,pos): import subprocess global Path global Read1 global Read2 global Nome global label Read1 = [] Read2 = [] Nome = [] Path = [] label = [] with open(file) as p: for i in p: lines = i.rstrip("\n").split(",") if lines[0] != "Name": Path.append(lines[10]) Nome.append(lines[0]) Read1.append(lines[7]) Read2.append(lines[8]) out = open("toRun.sh","w") out.write("#!/bin/bash\n") global pipe pipe =[] dizionario = {} for i in range(len(Nome)): dx =str("".join(Path[i])+ "/"+ "".join(Read1[i])) sn =str("".join(Path[i])+"/"+"".join(Read2[i])) if not os.path.exists(pos+"/"+i): os.makedirs(pos+"/"+i) print >>out, "cd " + pos +"\n" print >>out,"~/software/STAR_2.3.0e.Linux_x86_64_static/STAR --genomeDir /home/sbsuser/databases/Starhg19/GenomeDir/ --runMode alignReads --readFilesIn "+ dx +" "+ ""+ sn +" --runThreadN 12 --readFilesCommand zcat " +"\n" step_1_out =["~/software/STAR_2.3.0e.Linux_x86_64_static/STAR --genomeDir /home/sbsuser/databases/Starhg19/GenomeDir/ --runMode alignReads --readFilesIn % s %s --runThreadN 12 --readFilesCommand zcat "%(dx,dn)] print >>out,"cd " +" $PWD"+"/"+ "hg19_second/" +"\n" print >>out,"~/software/STAR_2.3.0e.Linux_x86_64_static/STAR --runMode genomeGenerate --genomeDir"+" $PWD"+"/"+ "hg19_second/ --genomeFastaFiles ~/databases/bowtie2Database/hg19.fa --sjdbFileChrStartEnd " +"$PWD"+"/"+ "SJ. out.tab" +" --sjdbOverhang 49 --runThreadN 12" +"\n" pipe.append("~/software/STAR_2.3.0e.Linux_x86_64_static/STAR --genomeDir /home/sbsuser/databases/Starhg19/GenomeDir/ --runMode alignReads --readFilesIn "+ dx +" "+ ""+ sn +" --runThreadN 12 --readFilesCommand zcat ") print >>out,"cd .." + "\n" print >>out,"~/software/STAR_2.3.0e.Linux_x86_64_static/STAR --genomeDir"+ " $PWD"+"/"+ "hg19_second/GenomeDir/ --runMode alignReads --readFilesIn "+ dx +" "+ ""+ sn +" --runThreadN 12 --readFilesCommand zcat " +"\n" dizionario.setdefault() # return Nome,Path,Read1,Read1 This isthe function I wrote but with this way I'm only able to write a bash script.. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] How to count vehicle? I'm trying but my code don't increasing..
Hello, I'm trying to counting vehicle, but I can't increasing it, I use python 2.7.6 and opencv 2.4.9 Here the code: import cv2 bgsMOG = cv2.BackgroundSubtractorMOG2(500,30,True) cap = cv2.VideoCapture("d:\MOV_5680.avi") counter=0 if cap: while True: ret, frame = cap.read() if ret: fgmask = bgsMOG.apply(frame, None, 0.01) cv2.line(frame,(20,170),(320,170),(175,175,0),1) contours, hierarchy = cv2.findContours(fgmask, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) ax1=20 #coordinate of line where vehicle will be count if intersect ay1=170 ax2=320 ay2=170 try: hierarchy = hierarchy[0] except: hierarchy = [] for contour, hier in zip(contours, hierarchy): (x,y,w,h) = cv2.boundingRect(contour) if w > 10 and h > 15: cv2.rectangle(frame, (x,y), (x+w,y+h), (180, 0, 0), 1) x1=w/2 #to find centroid y1=h/2 cx=x+x1 cy=y+y1 centroid=(cx,cy) cv2.circle(frame,(int(cx),int(cy)),1,(0,255,0),-1) dy=cy-170 #my first code to increase counter if dy==0: if (cx<=320)and(cx>=70): counter=counter+1 if cy==170: cv2.putText(frame, str(counter),(10,150), cv2.FONT_HERSHEY_SIMPLEX,2, (255, 0, 0), 1, True) #cv2.namedWindow('Output',cv2.cv.CV_WINDOW_NORMAL) #cv2.resizeWindow('Output',320,180) cv2.imshow('Output', frame) cv2.imshow('FGMASK', fgmask) key = cv2.waitKey(100) if key == ord('q'): break cap.release() cv2.destroyAllWindows() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] How to count vehicle? I'm trying but my code don't increasing..
Hello, I'm trying to counting vehicle, but I can't increasing it, I use python 2.7.6 and opencv 2.4.9 Here the code: import cv2 bgsMOG = cv2.BackgroundSubtractorMOG2(500,30,True) cap = cv2.VideoCapture("d:\MOV_5680.avi") counter=0 if cap: while True: ret, frame = cap.read() if ret: fgmask = bgsMOG.apply(frame, None, 0.01) cv2.line(frame,(20,170),(320,170),(175,175,0),1) contours, hierarchy = cv2.findContours(fgmask, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) ax1=20 #coordinate of line where vehicle will be count if intersect ay1=170 ax2=320 ay2=170 try: hierarchy = hierarchy[0] except: hierarchy = [] for contour, hier in zip(contours, hierarchy): (x,y,w,h) = cv2.boundingRect(contour) if w > 10 and h > 15: cv2.rectangle(frame, (x,y), (x+w,y+h), (180, 0, 0), 1) x1=w/2 #to find centroid y1=h/2 cx=x+x1 cy=y+y1 centroid=(cx,cy) cv2.circle(frame,(int(cx),int(cy)),1,(0,255,0),-1) dy=cy-170 #my first try to increase counter, not work if dy==0: if (cx<=320)and(cx>=70): counter=counter+1 if cy==170: #my second try to increasing, not work too counter=counter+1 cv2.putText(frame, str(counter),(10,150), cv2.FONT_HERSHEY_SIMPLEX,2, (255, 0, 0), 1, True) cv2.imshow('Output', frame) cv2.imshow('FGMASK', fgmask) key = cv2.waitKey(100) if key == ord('q'): break cap.release() cv2.destroyAllWindows() don't have error but I can't increasing the counter, please help me.. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how import a module upon instantiation of a class?
On 01/09/14 15:13, Steven D'Aprano wrote: To make it a global name, you need the global keyword: py> def cheese(): # take two ... global string ... import string ... py> cheese() py> string And co ing back to Albert's original request this little insight made me try something and it seems to work... You can assign the name inside the class, thus providing the class level import that Albert wanted: >>> class C: ... def __init__(self): ... import sys ... self.__sys = sys ... def printSys(self): ... print self.__sys.path ... >>> c = C() >>> sys Traceback (most recent call last): File "", line 1, in NameError: name 'sys' is not defined >>> c.__sys Traceback (most recent call last): File "", line 1, in AttributeError: C instance has no attribute '__sys' >>> c.printSys() ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', ... So now you have a module imported inside a class such that it is only visible inside objects of that class. Now why you would want that I'm less sure, but you can do it... HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Good Text Editor/IDE for Python
On 01/09/14 14:59, Steven D'Aprano wrote: (Question: anyone know how to tell readline to jump straight to a particular history line? M-< goes to the oldest line in the history, and M-> goes to the most recent, but how would I go straight to line 87?) Bash readline allows backwards searches of history with Ctrl-r - does that work? Not quite the same as goto line I know but maybe it would help? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to count vehicle? I'm trying but my code don't increasing..
On 01/09/14 16:13, Whees Northbee wrote: Hello, I'm trying to counting vehicle, but I can't increasing it, I use python 2.7.6 and opencv 2.4.9 I don;t understand what you mean. There is no vehicle in your code? The code is overly complex for me to read through and it uses a module that I don't have so I'm not even attempting to run it... And it looks like it has a syntax error too - an if block missing. Can you provide more details about what is happening? Also try inserting some print statements so that you can see what your code is doing. That way you might see the problem yourself. import cv2 bgsMOG = cv2.BackgroundSubtractorMOG2(500,30,True) cap = cv2.VideoCapture("d:\MOV_5680.avi") counter=0 if cap: while True: ret, frame = cap.read() if ret: fgmask = bgsMOG.apply(frame, None, 0.01) cv2.line(frame,(20,170),(320,170),(175,175,0),1) contours, hierarchy = cv2.findContours(fgmask, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) ax1=20 #coordinate of line where vehicle will be count if intersect ay1=170 ax2=320 ay2=170 try: hierarchy = hierarchy[0] except: hierarchy = [] for contour, hier in zip(contours, hierarchy): (x,y,w,h) = cv2.boundingRect(contour) if w > 10 and h > 15: cv2.rectangle(frame, (x,y), (x+w,y+h), (180, 0, 0), 1) x1=w/2 #to find centroid y1=h/2 cx=x+x1 cy=y+y1 centroid=(cx,cy) cv2.circle(frame,(int(cx),int(cy)),1,(0,255,0),-1) dy=cy-170 #my first code to increase counter if dy==0: if (cx<=320)and(cx>=70): counter=counter+1 if cy==170: cv2.putText(frame, str(counter),(10,150), cv2.FONT_HERSHEY_SIMPLEX,2, (255, 0, 0), 1, True) #cv2.namedWindow('Output',cv2.cv.CV_WINDOW_NORMAL) #cv2.resizeWindow('Output',320,180) cv2.imshow('Output', frame) cv2.imshow('FGMASK', fgmask) key = cv2.waitKey(100) if key == ord('q'): break cap.release() cv2.destroyAllWindows() -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how import a module upon instantiation of a class?
On Mon, Sep 01, 2014 at 04:55:09PM +0100, Alan Gauld wrote: > And co ing back to Albert's original request this little insight made me > try something and it seems to work... > > You can assign the name inside the class, thus providing the class level > import that Albert wanted: > > >>> class C: > ... def __init__(self): > ... import sys > ... self.__sys = sys > ... def printSys(self): > ... print self.__sys.path > ... > >>> c = C() > >>> sys > Traceback (most recent call last): > File "", line 1, in > NameError: name 'sys' is not defined > >>> c.__sys > Traceback (most recent call last): > File "", line 1, in > AttributeError: C instance has no attribute '__sys' That's just Python's regular old "name mangling" in progress. If you create a method or attribute with a name starting with two underscores, but not ending with two underscores, the Python compiler mangles references to it. This is quite lame protection from accidental name clashes, but it can easily be over-come. Try this: c._C__sys Python simply stuffs a single underscore and the name of the class in front of the double leading underscore attribute name. It's enough to prevent 99% of accidental name clashes, but anyone who wants to can defeat it. > >>> c.printSys() > ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', ... > > So now you have a module imported inside a class such that it > is only visible inside objects of that class. Not quite invisible. More like standing in the corner covered with a white sheet. So long as nobody peeks under the sheet, nobody can see it. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to count vehicle? I'm trying but my code don't increasing..
On Mon, Sep 01, 2014 at 10:20:02PM +0700, Whees Northbee wrote: > for contour, hier in zip(contours, hierarchy): > (x,y,w,h) = cv2.boundingRect(contour) What is the value of y here? Insert a line "print(x, y, w, h)" so you can see what values they take. > if w > 10 and h > 15: Is this condition ever true? Perhaps this block of code never gets executed at all. > cv2.rectangle(frame, (x,y), (x+w,y+h), (180, 0, 0), 1) > x1=w/2 #to find centroid > y1=h/2 > cx=x+x1 > cy=y+y1 What's the value of cy? > centroid=(cx,cy) > cv2.circle(frame,(int(cx),int(cy)),1,(0,255,0),-1) > dy=cy-170 #my first try to increase counter, not work > if dy==0: > if (cx<=320)and(cx>=70): > counter=counter+1 That's better written as: if 70 <= cx <= 320: counter += 1 > if cy==170: #my second try to increasing, not work too > counter=counter+1 What values does cy take? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Good Text Editor/IDE for Python
On Sun, Aug 31, 2014 at 5:12 PM, Juan Christian wrote: > I've been using PyCharm to code in Python but it seems a bit "overpowered" > for this task, and there are some annoying bugs. I used Sublime Text 2 in > the past, but it seems to be dead now (last update was JUN/2013), so I don't > really know any good options. > > What do you guys use to code? If you're already familiar with Eclipse, then the PyDev plugin may be appropriate. http://pydev.org/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Good Text Editor/IDE for Python
Thanks everyone. I will try tabhistory, since I'm using Python 3.4.1 it comes built-in in the IDLE, as the site says, "(Python 3.4 comes with these enabled as standard.)", so, I'll definitely try IDLE. I like PyCharm but I prefer a "calm and clear" environment in order to code. I'll keep using Sublime Text 3 (maybe ST3 isn't dead as I thought) + cmd.exe for coding, and maybe IDLE if I like and feel comfortable about it. On Mon, Sep 1, 2014 at 1:40 PM, Danny Yoo wrote: > On Sun, Aug 31, 2014 at 5:12 PM, Juan Christian > wrote: > > I've been using PyCharm to code in Python but it seems a bit > "overpowered" > > for this task, and there are some annoying bugs. I used Sublime Text 2 in > > the past, but it seems to be dead now (last update was JUN/2013), so I > don't > > really know any good options. > > > > What do you guys use to code? > > > If you're already familiar with Eclipse, then the PyDev plugin may be > appropriate. > > http://pydev.org/ > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to count vehicle? I'm trying but my code don't increasing..
>What is the value of y here? (x,y,w,h)=cv2.boundingRect(contour), where x,y is the left up position from contour, and w,h is width and height of contour.. >* if w > 10 and h > 15:* *this code I used, because there's a lot small blob from video shaking, or the movement of trees.. And yes, the condition is true* >* cv2.rectangle(frame, (x,y), (x+w,y+h), (180, 0, 0), 1) *>* x1=w/2 #to find centroid *>* y1=h/2 *>* cx=x+x1 *>* cy=y+y1* >What's the value of cy? cy and cx is the coordinate of center of rectangle.. the value is cartesian coordinate like (136,60) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to count vehicle? I'm trying but my code don't increasing..
There's no vehicle in my code, my video just contain vehicles so I think I don't need to use haar classifier, so I'm just do background subtraction to get foreground which is vehicle movement because there's no other movement except vehicle and maybe little movement from trees... I just use opencv module, like to do background subtraction.. No, the code don't have any error. The code is working smoothly to detecting vehicle and make rectangle of vehicle, and I find center point of rectangle at (cx,cy).. I draw manually a line in video at coordinate (20,170) to (320,170).. When each of the rectangle vehicle cross or intersect with that line, I want to count it as 1.. I already try: *)I think, since the line is in the same y coordinate, so if the center (cx,cy), cy=line y coordinate, the count increase if cy==170: counter=counter+1 it doesn't work, no error but the counter stuck at 0 Second try: *)I try to find distance between (cx,cy) and that line, if the distance is 0, counter increase dy=cy-170 #170 is y coordinate of line if dy==0: if (cx<=320) and (cx>=70): counter=counter+1 don't have error, but the counter sometime add sometime no.. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Good Text Editor/IDE for Python
On 01/09/14 19:34, Juan Christian wrote: + cmd.exe for coding, If you are not a cmd.exe regular make sure you read the help page and enable all the extra features that are turned off by default... Things like file and command completion for example. It makes cmd.exe a much more usable place. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Good Text Editor/IDE for Python
I'm going to test a linter for ST3, but there are tons of options for Python and I got confused. https://sublime.wbond.net/packages/SublimeLinter-pyflakes https://sublime.wbond.net/packages/SublimeLinter-pylint https://sublime.wbond.net/packages/SublimeLinter-pep8 https://sublime.wbond.net/packages/SublimeLinter-pep257 https://sublime.wbond.net/packages/SublimeLinter-flake8 If I remember correctly, PEP8 is a "Style Guide for Python Code", good practices for coding and similar. What about pep257, flak8, pylint, and others? Which one is the best to use/follow? On Mon, Sep 1, 2014 at 3:45 PM, Alan Gauld wrote: > On 01/09/14 19:34, Juan Christian wrote: > > + cmd.exe for coding, >> > > If you are not a cmd.exe regular make sure you read the help page > and enable all the extra features that are turned off by default... > Things like file and command completion for example. > > It makes cmd.exe a much more usable place. > > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.flickr.com/photos/alangauldphotos > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to count vehicle? I'm trying but my code don't increasing..
On Tue, Sep 02, 2014 at 12:54:03AM +0700, Whees Northbee wrote: > >What is the value of y here? > (x,y,w,h)=cv2.boundingRect(contour), where x,y is the left up position from > contour, and w,h is width and height of contour.. That's not the value of y. You have just repeated the same line of code that provides the values. What are they? y = 1? y = 10? Who knows? Do you know what values y has? > >* if w > 10 and h > 15:* > > *this code I used, because there's a lot small blob from video > shaking, or the movement of trees.. And yes, the condition is true* How do you know? > >* cv2.rectangle(frame, (x,y), (x+w,y+h), (180, 0, 0), 1) > *>* x1=w/2 #to find centroid > *>* y1=h/2 > *>* cx=x+x1 > *>* cy=y+y1* > > >What's the value of cy? > cy and cx is the coordinate of center of rectangle.. the value is cartesian > coordinate like (136,60) You're testing for cy == 170. If the value of cy is 60, that doesn't equal 170. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to count vehicle? I'm trying but my code don't increasing..
On Tue, Sep 02, 2014 at 01:15:59AM +0700, Whees Northbee wrote: > There's no vehicle in my code, my video just contain vehicles so I think I > don't need to use haar classifier, so I'm just do background subtraction to > get foreground which is vehicle movement because there's no other movement > except vehicle and maybe little movement from trees... Do you realise that this is a list for learning Python? We're not experts on video analysis. Probably nobody here except you has even the faintest idea what a Haar classifier is or whether you need one or not. > I just use opencv module, like to do background subtraction.. > No, the code don't have any error. If the code doesn't have any errors, then it must be working correctly. > The code is working smoothly to detecting vehicle and make rectangle of > vehicle, How do you know? What part of your code shows you that it is correctly detecting vehicles? > and I find center point of rectangle at (cx,cy).. > I draw manually a line in video at coordinate (20,170) to (320,170).. > When each of the rectangle vehicle cross or intersect with that line, I > want to count it as 1.. > I already try: > > *)I think, since the line is in the same y coordinate, so if the center > (cx,cy), cy=line y coordinate, the count increase > > if cy==170: > counter=counter+1 > > it doesn't work, no error but the counter stuck at 0 How fast are the vehicles moving? What is the resolution of the measurements? > Second try: > *)I try to find distance between (cx,cy) and that line, if the distance is > 0, counter increase > > dy=cy-170 #170 is y coordinate of line > if dy==0: > if (cx<=320) and (cx>=70): > counter=counter+1 > > don't have error, but the counter sometime add sometime no.. Earlier, you said that it never worked. Now you say it sometimes works. Which is correct? There is no difference between: cy == 170 and (cy - 170) == 0 So the question is, how do you know that cy ever equals 170? Suppose the vehicle is moving towards the line. In the first frame, cy = 300. In the second frame, 250. In the third frame, 200. Then, 150, 100, 50 and then it's no longer in the picture. There is never a time that cy == 170. The logic of your code is wrong. You need to think of a different way to solve this problem. Or, I could be completely wrong. I don't know, because I don't understand how this video processing works. I am just guessing. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to count vehicle? I'm trying but my code don't increasing..
- Original Message - > From: Steven D'Aprano > To: tutor@python.org > Cc: > Sent: Monday, September 1, 2014 9:47 PM > Subject: Re: [Tutor] How to count vehicle? I'm trying but my code don't > increasing.. > > On Tue, Sep 02, 2014 at 01:15:59AM +0700, Whees Northbee wrote: >> There's no vehicle in my code, my video just contain vehicles so I > think I >> don't need to use haar classifier, so I'm just do background > subtraction to >> get foreground which is vehicle movement because there's no other > movement >> except vehicle and maybe little movement from trees... > > Do you realise that this is a list for learning Python? We're not > experts on video analysis. Probably nobody here except you has even the > faintest idea what a Haar classifier is or whether you need one or not. Yep, never heard about it until today :-) http://en.wikipedia.org/wiki/Haar-like_features ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Good Text Editor/IDE for Python
On 01Sep2014 23:59, Steven D'Aprano wrote: On Mon, Sep 01, 2014 at 11:57:08AM +1000, Cameron Simpson wrote: On 01Sep2014 11:13, Steven D'Aprano wrote: >Just recently, I've customised my interactive Python with a powerful set >of tab completion commands, similar to that provided by IPython. While >typing, if I hit tab, it will try to complete the current variable, >function, module or file name. I don't know how I programmed without it >all these years :-) I must try that sometime. Please do :-) You can get the module from here: http://code.google.com/p/tabhistory/ Or directly using Mercurial. Run this command at the shell: hg clone https://code.google.com/p/tabhistory/ [...] Installed. Wow. That's really handy! Thanks! Cameron Simpson Microsoft Mail: as far from RFC-822 as you can get and still pretend to care. - Abby Franquemont-Guillory ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] python launcher
Until now I have used IDLE to write and run programs. I decided it was time to do it the hard way and use only a Terminal and a plain text editor, TextWrangler. I have Python 3.4.1 and OS 10.8.5. When I run the script by calling for the interpreter in the terminal with the script as the parameter (e.g. python3 shares.py), it runs fine. This is the output: corrupt record.removed corrupt record.removed corrupt record.removed ['description', 'symbol', 'current price', 'number of units'] List shares Buy shares Sell shares Update prices ridfx 21.98 833.592135342 18322.36 dodfx 46.99 390.964829507 18371.44 dfsvx 36.87 499.060771965 18400.37 pplix 15.42 1189.216568817 18337.72 total 73431.89 However, when I run it by using the Python Launcher, this is the result: corrupt record.removed corrupt record.removed corrupt record.removed ['description', 'symbol', 'current price', 'number of units'] ('\t\t\t', 'List shares') ('\t\t\t', 'Buy shares') ('\t\t\t', 'Sell shares') ('\t\t\t', 'Update prices') ('ridfx', '21.98', '833.592135342', 18322.36) ('dodfx', '46.99', '390.964829507', 18371.44) ('pplix', '15.42', '1189.216568817', 18337.72) ('dfsvx', '36.87', '499.060771965', 18400.37) ('total', 73431.89) Exit status: 0 logout [Process completed] Why the difference ? All the output was taken care of by the Print function. Jan Schreuder ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Good Text Editor/IDE for Python
So guys, I'll be using this one ( https://sublime.wbond.net/packages/SublimeLinter-flake8), why? Because acording to Python Package Index ( https://pypi.python.org/pypi/flake8), this linter uses: 1. PyFlakes 2. pep8 3. Ned Batchelder's McCabe script I don't have a clue what the n3 does, but the first two are familiar to me. That's enough for code style and error checking, right? On Mon, Sep 1, 2014 at 6:35 PM, Cameron Simpson wrote: > On 01Sep2014 23:59, Steven D'Aprano wrote: > >> On Mon, Sep 01, 2014 at 11:57:08AM +1000, Cameron Simpson wrote: >> >>> On 01Sep2014 11:13, Steven D'Aprano wrote: >>> >Just recently, I've customised my interactive Python with a powerful set >>> >of tab completion commands, similar to that provided by IPython. While >>> >typing, if I hit tab, it will try to complete the current variable, >>> >function, module or file name. I don't know how I programmed without it >>> >all these years :-) >>> >>> I must try that sometime. >>> >> >> Please do :-) >> >> You can get the module from here: >> http://code.google.com/p/tabhistory/ >> >> Or directly using Mercurial. Run this command at the shell: >> hg clone https://code.google.com/p/tabhistory/ >> > [...] > > Installed. Wow. That's really handy! > > Thanks! > Cameron Simpson > > Microsoft Mail: as far from RFC-822 as you can get and still pretend to > care. > - Abby Franquemont-Guillory > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python launcher
Jan Karel Schreuder wrote: > Until now I have used IDLE to write and run programs. I decided it was > time to do it the hard way and use only a Terminal and a plain text > editor, TextWrangler. I have Python 3.4.1 and OS 10.8.5. When I run the > script by calling for the interpreter in the terminal with the script as > the parameter (e.g. python3 shares.py), it runs fine. This is the output: > > corrupt record.removed > corrupt record.removed > corrupt record.removed > ['description', 'symbol', 'current price', 'number of units'] > List shares > Buy shares > Sell shares > Update prices > ridfx 21.98 833.592135342 18322.36 > dodfx 46.99 390.964829507 18371.44 > dfsvx 36.87 499.060771965 18400.37 > pplix 15.42 1189.216568817 18337.72 > total 73431.89 > > However, when I run it by using the Python Launcher, this is the result: > > corrupt record.removed > corrupt record.removed > corrupt record.removed > ['description', 'symbol', 'current price', 'number of units'] > ('\t\t\t', 'List shares') > ('\t\t\t', 'Buy shares') > ('\t\t\t', 'Sell shares') > ('\t\t\t', 'Update prices') > ('ridfx', '21.98', '833.592135342', 18322.36) > ('dodfx', '46.99', '390.964829507', 18371.44) > ('pplix', '15.42', '1189.216568817', 18337.72) > ('dfsvx', '36.87', '499.060771965', 18400.37) > ('total', 73431.89) > Exit status: 0 > logout > > [Process completed] > > Why the difference ? All the output was taken care of by the Print > function. In Python 3 print is a function, so print(1, 2) will invoke print with two arguments and display 1 2 In Python 2 print is a statement, to display the two numbers you have to write print 1, 2 while in print(1, 2) (1, 2) is interpreted as a single argument and the tuple (1, 2) is printed. I'm not familiar with the Mac, so I don't know how to convince the "launcher" to use Python 3 instead of Python 2. I'd try adding #!/usr/bin/env python3 as the first line of your script. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Good Text Editor/IDE for Python
Forget guys, we have the true winner, Anaconda ( https://sublime.wbond.net/packages/Anaconda) Anaconda turns your Sublime Text 3 in a full featured Python development IDE including autocompletion, code linting, IDE features, autopep8 formating, McCabe complexity checker and Vagrant for Sublime Text 3 using Jedi, PyFlakes, pep8, PyLint, pep257 and McCabe that will never freeze your Sublime Text 3. All I want in one place, better than that only if it codes for me. =p On Mon, Sep 1, 2014 at 9:25 PM, Juan Christian wrote: > So guys, I'll be using this one ( > https://sublime.wbond.net/packages/SublimeLinter-flake8), why? > > Because acording to Python Package Index ( > https://pypi.python.org/pypi/flake8), this linter uses: > > 1. PyFlakes > 2. pep8 > 3. Ned Batchelder's McCabe script > > I don't have a clue what the n3 does, but the first two are familiar to > me. That's enough for code style and error checking, right? > > > On Mon, Sep 1, 2014 at 6:35 PM, Cameron Simpson wrote: > >> On 01Sep2014 23:59, Steven D'Aprano wrote: >> >>> On Mon, Sep 01, 2014 at 11:57:08AM +1000, Cameron Simpson wrote: >>> On 01Sep2014 11:13, Steven D'Aprano wrote: >Just recently, I've customised my interactive Python with a powerful set >of tab completion commands, similar to that provided by IPython. While >typing, if I hit tab, it will try to complete the current variable, >function, module or file name. I don't know how I programmed without it >all these years :-) I must try that sometime. >>> >>> Please do :-) >>> >>> You can get the module from here: >>> http://code.google.com/p/tabhistory/ >>> >>> Or directly using Mercurial. Run this command at the shell: >>> hg clone https://code.google.com/p/tabhistory/ >>> >> [...] >> >> Installed. Wow. That's really handy! >> >> Thanks! >> Cameron Simpson >> >> Microsoft Mail: as far from RFC-822 as you can get and still pretend to >> care. >> - Abby Franquemont-Guillory >> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> https://mail.python.org/mailman/listinfo/tutor >> > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor