Re: New to Python, Help to get script working?
On Monday, December 16, 2013 2:52:05 AM UTC-5, Mark wrote: On Monday, December 16, 2013 2:48:56 AM UTC-5, Mark wrote: On Monday, December 16, 2013 2:43:45 AM UTC-5, Mark wrote: On Monday, December 16, 2013 2:09:38 AM UTC-5, Mark wrote: On Sunday, December 15, 2013 9:33:17 PM UTC-5, Chris Angelico wrote: On Mon, Dec 16, 2013 at 12:37 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Step 1: replace the modified version of the script with a known good copy. Actually, this might be where the problem is, unfortunately. Not the OP's fault at all. I went and looked at the post linked to, and it has buggy indentation. (Quite possibly indicates that the author has two-space tabs, and didn't notice a bug slipping in. I dunno.) Along the way, though, I learned that the script in question is entirely for generating fake twitch.tv viewers so as to get your stream highlighted fraudulently, so I'm rather less inclined to help. Got a legitimate use for this, or are you just trying to cheat your way to fame? ChrisA Thanks for the reply, the answer is yes and no, i already have about 2400 followers and half mil views, i just wanted to see if i could get it to work. So after taking everybody's advice, fixed the indentation as mentioned by the expert above. :) After, this is what i came up with Traceback (most recent call last): File C:\Python27\Scripts\Twitch.py, line 9, in module numberOfViewers = int(sys.argv[1]) IndexError: list index out of range Is this where i would plug in the variables to make it work? I'm not quite sure about how you would plug in those numbers okay so i kinda get it now, running it in cmd, i use the following command - python twitch.py 10 10. I am running it within the scripts directory. I get the following error in cmd: Syntax Error: invalid syntax python twitch.py 10 10 File stdin line 1 python twitch.py 10 10 is there a more effecient way of doing this? I just hold shift and right click to run cmd from the folder, File is located in C:\Python27\Scripts It was my understanding that you need to meet the arguments by running the in cmd with the numbers after? I am sorry to show my true noobyness and really appreciate the help. Here is a link to the actual file, maybe you can look at it and see if it looks good? Should i change anything else in the file to make it work theoretically or is it all done when you run it? http://www.mediafire.com/view/3m10s9rwvatxd96/twitch.py -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with the BeautifulSoup problem, please
On Monday, December 16, 2013 2:41:08 PM UTC+8, seas...@gmail.com wrote: I need to replace all tag b with span after ■. But the result from below is '■ span style=REPLACED/span / font/font' Can you explain what I did wrong, please. s = '■bA/b bB/b bC/b bD/b / font/font' soup = BeautifulSoup(s) for i in soup.find_all(text='■'): tag = soup.new_tag('span') tag['style'] = 'REPLACE' for ii in i.find_next_siblings(): if ii.name=='font' or str(ii).lstrip('')[0:1]=='/': break else: if ii.name=='b': tag.string=ii.string print(ii.replace_with(tag)) print(soup) I think you should try some descent free editors such as notepad++ for your source codes to replace trivial strings without programmig. -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
On Monday, December 16, 2013 2:55:23 AM UTC-5, Mark wrote: On Monday, December 16, 2013 2:52:05 AM UTC-5, Mark wrote: On Monday, December 16, 2013 2:48:56 AM UTC-5, Mark wrote: On Monday, December 16, 2013 2:43:45 AM UTC-5, Mark wrote: On Monday, December 16, 2013 2:09:38 AM UTC-5, Mark wrote: On Sunday, December 15, 2013 9:33:17 PM UTC-5, Chris Angelico wrote: On Mon, Dec 16, 2013 at 12:37 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Step 1: replace the modified version of the script with a known good copy. Actually, this might be where the problem is, unfortunately. Not the OP's fault at all. I went and looked at the post linked to, and it has buggy indentation. (Quite possibly indicates that the author has two-space tabs, and didn't notice a bug slipping in. I dunno.) Along the way, though, I learned that the script in question is entirely for generating fake twitch.tv viewers so as to get your stream highlighted fraudulently, so I'm rather less inclined to help. Got a legitimate use for this, or are you just trying to cheat your way to fame? ChrisA Thanks for the reply, the answer is yes and no, i already have about 2400 followers and half mil views, i just wanted to see if i could get it to work. So after taking everybody's advice, fixed the indentation as mentioned by the expert above. :) After, this is what i came up with
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
Michael Torrie wrote: I think PyQt is slowly being pushed aside in favor of PySide, which is more license-friendly for use in closed or open projects. I would recommend using PySide unless PyQt is a requirement for your project. That's not the impression I get from the PySide mailing lists. Work seems slow now everyone is a volunteer. For example, Qt 5 is not yet supported (there's no effort towards this according to the mailing list) and bugs seem to take a long time to be fixed. PyQt support is much better, even when I'm using it for a free project. Jeremy -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
Mark markyshiz...@gmail.com wrote in message news:4c2822b4-d95c-4735-af12-55ac5ff2f...@googlegroups.com... On Monday, December 16, 2013 2:55:23 AM UTC-5, Mark wrote: If i just try to double click the script, i get an index error, i can barely see the window it disappears so fast, but thats what I see. I haven't really been following this thread, but I assume you are on Windows. If so, you can open a Command Prompt from All Programs/Accessories, 'cd' to the folder containing your script, and type in the script name. It will start, crash, and display the error, but the window will stay open, so you will be able to read the full traceback. Normally the traceback provides enough clues that you can figure out for yourself what the problem is. But if you still cannot solve it, copy/paste the entire traceback and send it here. The chances are that someone can help. BTW, did you notice that I removed the bulk of your original message, and left behind just enough to provide a context for your question and for my reply? This is good etiquette, and others will appreciate your doing the same. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with the BeautifulSoup problem, please
seas...@gmail.com於 2013年12月16日星期一UTC+8下午2時41分08秒寫道: I need to replace all tag b with span after ■. But the result from below is '■ span style=REPLACED/span / font/font' Can you explain what I did wrong, please. s = '■bA/b bB/b bC/b bD/b / font/font' soup = BeautifulSoup(s) for i in soup.find_all(text='■'): tag = soup.new_tag('span') tag['style'] = 'REPLACE' for ii in i.find_next_siblings(): if ii.name=='font' or str(ii).lstrip('')[0:1]=='/': break else: if ii.name=='b': tag.string=ii.string print(ii.replace_with(tag)) print(soup) the point is the result seems wrong. I don't know if that is my problem. I simplify the code to emphasize the problem, there's no way an editor can do what I wanna do. -- https://mail.python.org/mailman/listinfo/python-list
Re: Wrapping around a list in Python.
shengjie.sheng...@live.com wrote: The idea is to grab the last 4 elements of the array. However i have an array that contains a few hundred elements in it. And the values continues to .append over time. How would i be able to display the last 4 elements of the array under such a condition? Use a deque: from collections import deque last_four = deque(maxlen=4) for i in range(10): ... last_four.append(i) ... last_four deque([6, 7, 8, 9], maxlen=4) last_four.extend(range(100, 200)) last_four deque([196, 197, 198, 199], maxlen=4) last_four.append(42) last_four deque([197, 198, 199, 42], maxlen=4) -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing values of counter in python 3.3
On 16/12/2013 02:40, Roy Smith wrote: In article 905d6e7e-6748-42dd-8b63-d80a4d175...@googlegroups.com, rusi rustompm...@gmail.com wrote: On Monday, December 16, 2013 7:29:31 AM UTC+5:30, alex23 wrote: # Need to compare values of counter and reject in function/routine in value in counter2 is higher then value in counter1 for a current key [(k,Counter2[k]) for k in Counter2 - Counter1] Why not just? Counter2 - Counter1 And if you want to uncounterify it then dict(Counter2 - Counter1) Counters are awesome. Yes -- agreed. But 'counter' is a strange name -- after checking whether 'bag' and 'multiset' are there in the library, I would not think to check anything else. Bag and multiset are names only CS weenies would think to look for. Counter is the name for the rest of us :-) Give me bag or multiset any day of the week, it's blatantly obvious what they do. Counter, what the heck? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
On 16/12/2013 08:02, Mark wrote: The record for double spaced google crap, congratulations. Mind you, it's a great new game this, Spot the Text, much better than I Spy!!! On Monday, December 16, 2013 2:55:23 AM UTC-5, Mark wrote: On Monday, December 16, 2013 2:52:05 AM UTC-5, Mark wrote: On Monday, December 16, 2013 2:48:56 AM UTC-5, Mark wrote: On Monday, December 16, 2013 2:43:45 AM UTC-5, Mark wrote: On Monday, December 16, 2013 2:09:38 AM UTC-5, Mark wrote: On Sunday, December 15, 2013 9:33:17 PM UTC-5, Chris Angelico wrote: On Mon, Dec 16, 2013 at 12:37 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Step 1: replace the modified version of the script with a known good copy. Actually, this might be where the problem is, unfortunately. Not the OP's fault at all. I went and looked at the post linked to, and it has buggy indentation. (Quite possibly indicates that the author has two-space tabs, and didn't notice a bug slipping in. I dunno.) Along the way, though, I learned that the script in question is entirely for generating fake twitch.tv viewers so as to get your stream highlighted fraudulently, so I'm rather less inclined to help. Got a legitimate use for this, or are you just trying to cheat your way to fame? ChrisA Thanks for the reply, the answer is yes and no, i already have about 2400 followers and half mil views, i just wanted to see if i could get it to work. So after taking everybody's advice, fixed the indentation as mentioned by the expert above. :) After, this is what i came up with Traceback (most recent call last): File C:\Python27\Scripts\Twitch.py, line 9, in module numberOfViewers = int(sys.argv[1]) IndexError: list index out of range Is this where i would plug in the variables to make it work? I'm not quite sure about how you would plug in those numbers okay so i kinda get it now, running it in cmd, i use the following command - python twitch.py 10 10. I am running it within the scripts directory.
Re: Need Help with the BeautifulSoup problem, please
On 16.12.2013 07:41, seasp...@gmail.com wrote: I need to replace all tag b with span after ■. But the result frombelow is '■ span style=REPLACED/span / font/font' Can you explain what I did wrong, please. s = '■bA/b bB/b bC/b bD/b / font/font' soup = BeautifulSoup(s) for i in soup.find_all(text='■'): tag = soup.new_tag('span') tag['style'] = 'REPLACE' for ii in i.find_next_siblings(): if ii.name=='font' or str(ii).lstrip('')[0:1]=='/': break else: if ii.name=='b': tag.string=ii.string print(ii.replace_with(tag)) print(soup) You are only creating one new tag but as I understand your problem you want to replace each b-element with a new tag. Simply move the tag creating part: for i in soup.find_all(text='■'): for ii in i.find_next_siblings(): if ii.name=='font' or str(ii).lstrip('')[0:1]=='/': break else: if ii.name=='b': tag = soup.new_tag('span') tag['style'] = 'REPLACE' tag.string=ii.string print(ii.replace_with(tag)) And please read https://wiki.python.org/moin/GoogleGroupsPython if you want to continue using Google Groups for accessing this list. Bye, Andreas -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with the BeautifulSoup problem, please
8 Dihedral於 2013年12月16日星期一UTC+8下午4時02分42秒寫道: On Monday, December 16, 2013 2:41:08 PM UTC+8, seas...@gmail.com wrote: I need to replace all tag b with span after ■. But the result from below is '■ span style=REPLACED/span / font/font' Can you explain what I did wrong, please. s = '■bA/b bB/b bC/b bD/b / font/font' soup = BeautifulSoup(s) for i in soup.find_all(text='■'): tag = soup.new_tag('span') tag['style'] = 'REPLACE' for ii in i.find_next_siblings(): if ii.name=='font' or str(ii).lstrip('')[0:1]=='/': break else: if ii.name=='b': tag.string=ii.string print(ii.replace_with(tag)) print(soup) I think you should try some descent free editors such as notepad++ for your source codes to replace trivial strings without programmig. I think it's my fault, thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with the BeautifulSoup problem, please
seasp...@gmail.com wrote: I need to replace all tag b with span after ■. But the result from below is '■ span style=REPLACED/span / font/font' Can you explain what I did wrong, please. s = '■bA/b bB/b bC/b bD/b / font/font' soup = BeautifulSoup(s) for i in soup.find_all(text='■'): tag = soup.new_tag('span') tag['style'] = 'REPLACE' for ii in i.find_next_siblings(): if ii.name=='font' or str(ii).lstrip('')[0:1]=='/': break else: if ii.name=='b': tag.string=ii.string print(ii.replace_with(tag)) print(soup) It looks like you cannot reuse a tag. Try s = '■bA/b bB/b bC/b bD/b / font/font' soup = BeautifulSoup(s) for i in soup.find_all(text='■'): for ii in i.find_next_siblings(): if ii.name=='font' or str(ii).lstrip('')[0:1]=='/': break else: if ii.name=='b': tag = soup.new_tag('span') tag['style'] = 'REPLACE' tag.string=ii.string print(ii.replace_with(tag)) print(soup) -- https://mail.python.org/mailman/listinfo/python-list
Re: Wrapping around a list in Python.
On 16/12/2013 05:10, shengjie.sheng...@live.com wrote: On Monday, 16 December 2013 13:07:46 UTC+8, shengjie...@live.com wrote: Would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On 16/12/2013 05:08, Chris Angelico wrote: On Mon, Dec 16, 2013 at 3:51 PM, Michael Torrie torr...@gmail.com wrote: I think Python is a great overall application development language, especially for the GUI. First-class functions for callbacks make it very nice compared to other languages. Python is fast enough for full-blown apps too. Slow parts can be factored out to other languages. Python is sooo slow when it waits for the human. That pesky input() function can take *minutes* to return. It's terrible! Factor that out and your job's done. I've done the latter, but still can't fit all the data for my 100+ screens into a one liner, help please :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
Op donderdag 12 december 2013 22:23:22 UTC+1 schreef Dan Stromberg: On Thu, Dec 12, 2013 at 12:28 AM, Jean Dubois jeandubois...@gmail.com wrote: On Thursday, December 12, 2013 12:20:36 AM UTC+1, Dan Stromberg wrote: On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois jeandu...@gmail.com wrote: I have an ethernet-rs232 adapter which allows me to connect to a measurement instrument by means of netcat on a linux system. e.g. entering nc 10.128.59.63 7000 allows me to enter e.g. *IDN? after which I get an identification string of the measurement instrument back. I thought I could accomplish the same using the python module socket and tried out the sample program below which doesn't work however: Sockets reserve the right to split one socket.send() into multiple socket.recv()'s on the other end of the communication, or to aggregate multiple socket.send()'s into a single socket.recv() - pretty much any way the relevant IP stacks and communications equipment feel like for the sake of performance or reliability. The confusing thing about this is, it won't be done on every transmission - in fact, it'll probably happen rather seldom unless you're on a heavy loaded network or have some MTU issues (see Path MTU Discovery, and bear in mind that paths can change during a TCP session). But writing your code assuming it will never happen is a bad idea. For this reason, I wrote http://stromberg.dnsalias.org/~strombrg/bufsock.html , which abstracts away these complications, and actually makes things pretty simple. There are examples on the web page. HTH Dear Dan, Could you copy paste here the code for your function I have to add to my program? This is untested, but it should be something like the following: #!/usr/bin/env python A simple echo client import socket as socket_mod import bufsock as bufsock_mod host = '10.128.59.63' port = 7000 size = 10 socket = socket_mod.socket(socket.AF_INET, socket.SOCK_STREAM) socket.connect((host,port)) bufsock = bufsock_mod.bufsock(socket) bufsock.send('*IDN?') data = bufsock.recv(size) bufsock.close() print 'Received:', data You might look over http://stackoverflow.com/questions/19918307/retrieve-file-information-located-on-a-different-application-server-using-python/19918706#19918706 for a more complete example. So this is what I did: 1. svn checkout http://stromberg.dnsalias.org/svn/bufsock/ 2. cd ~/bufsock/trunk 3. I made this test-file buftest.py with the following contents: #!/usr/bin/env python A simple echo client import socket as socket_mod import bufsock as bufsock_mod host = '10.128.59.63' port = 7000 size = 10 socket = socket_mod.socket(socket.AF_INET, socket.SOCK_STREAM) socket.connect((host,port)) bufsock = bufsock_mod.bufsock(socket) bufsock.send('*IDN?') data = bufsock.recv(size) bufsock.close() print 'Received:', data 4. chmod +x buftest.py 5. ./buftest.py 6. This results in the following error message: Traceback (most recent call last): File ./buftest.py, line 11, in module socket = socket_mod.socket(socket.AF_INET, socket.SOCK_STREAM) NameError: name 'socket' is not defined Probably there is still something wrong, can anyone here help me further? kind regards, jean -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing values of counter in python 3.3
On Sun, Dec 15, 2013 at 6:32 PM, rusi rustompm...@gmail.com wrote: On Monday, December 16, 2013 7:29:31 AM UTC+5:30, alex23 wrote: # Need to compare values of counter and reject in function/routine in value in counter2 is higher then value in counter1 for a current key [(k,Counter2[k]) for k in Counter2 - Counter1] Why not just? Counter2 - Counter1 And if you want to uncounterify it then dict(Counter2 - Counter1) Because you get different counts. c1 = Counter('ab') c2 = Counter('aab') c2 - c1 Counter({'a': 1}) [(k, c2[k]) for k in c2 - c1] [('a', 2)] Counter subtraction is multiset subtraction, not set subtraction. -- Devin -- https://mail.python.org/mailman/listinfo/python-list
Re: Want guidance to set proxy please help
On Sun, 15 Dec 2013 20:29:55 -0800, Jai wrote: so , i need some step to set proxy so that my ip is not blocked by them This sounds like you're attempting to access a site other than for legitimate purposes. You probably want some 1337 script kiddies forum, not a serious programming newsgroup. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
hello, #!/usr/bin/env python A simple echo client import socket as socket_mod import bufsock as bufsock_mod [...] Traceback (most recent call last): File ./buftest.py, line 11, in module socket = socket_mod.socket(socket.AF_INET, socket.SOCK_STREAM) NameError: name 'socket' is not defined you should replace the socket.AF_INET to socket_mod.AF_INET, and socket.SOCK_STREAM to socket_mod.SOCK_STREAM, if you've imported socket modul as socket_mod. But this is just an idea... :) a. -- https://mail.python.org/mailman/listinfo/python-list
Re: Wrapping around a list in Python.
On Mon, 16 Dec 2013 15:59:32 +1100, Ben Finney wrote: shengjie.sheng...@live.com writes: Hi guys, I am trying to create a fixed list which would allow my values to be wrapped around it. This doesn't make a lot of sense to me, but I assume you have a purpose in mind for this. What is the purpose? Perhaps it will help the explanation if we know what it's for. For example i have 10 values : 0,1,2,3,4,5,6,7,8,9 Does this mean the input is a list, ‘[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]’? Or do you mean something else? What is the input? I need to create a list which contains 4 numbers and when the number exceeds the list, it would overwrite the first value. [0,1,2,3] [4,1,2,3] [5,4,1,2] That's three different lists. What is the input in each case? Under what circumstances would you expect each one to be produced? I suspect the OP means: first input is 0, list = [ 0 ] next input is 1, list = [ 0, 1 ] next input is 2, list = [ 0, 1, 2 ] next input is 3, list = [ 0, 1, 2, 3 ] next input is 4, list = [ 4, 1, 2, 3 ] next input is 5, list = [ 5, 4, 1, 2 ] But this is a bit daft, because he starts by appending, and when he hits overflow he starts prepending. What I think he should do is use collections.dequeue and a couple of helper functions to add and get data items. For a queue moving from position 0 to position 3 (left to right): from collections import deque q = dequeue([]) def add_to_queue( item, q ): if len( q ) is 4: q.pop() q.appendleft( item ) def get_next( q ): if len( q ) 0: return q.pop() return None To move from position 3 to position 0 (right to left), swap pop and appendleft for popleft and append. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Launching Helium: A Selenium wrapper that makes web automation 50% easier
Hi everyone, I'm working for a startup called BugFree Software and would like to announce that today we're launching our second product! Helium is a library that wraps around Selenium to simplify web automation. It does away with many of the technicalities involved with web scripting. For example: Here is a Selenium script. Can you guess what it does? ff = Firefox() ... text_area = ff.find_element_by_id(u_0_1q) text_area.send_keys(Hello World!) button = ff.find_element_by_class_name(_42g-) button.click() Here is the same script rewritten using Helium: start_firefox() ... write(Hello World!, into=Update Status) click(Post) Can you now guess what it does? That's right; It updates your Facebook status. In an extended comparison that we were invited to write for the December issue of Professional Tester (professionaltester.com), we found that an example script automating Gmail took 66% fewer lines of code and 75% less effort using Helium than with Selenium alone. You can find more information and download Helium from http://heliumhq.com. Any feedback would be highly appreciated. Hoping to hear your thoughts and comments, Michael Herrmann heliumhq.com -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
Such equipment often implements a telnet protocol. Have use try using the telnetlib module ? http://docs.python.org/2/library/telnetlib.html t = Telnet(host, port) t.write('*IDN?') print t.read_until('Whateverprompt') # you can use read_very_eager also JM Could you tell me how to install telnetlib on a linux-system (it's not available via apt-get install as I see it) kind regards, jean Please keep it on list, some other may have the same install issue or someone could have better insights on installing telnetlib. telnetlib is part of the standard modules in my Debian squeeze(python 2.5). Looking at the doc, it looks like it's available for python 3 as well. Strange that you don't have it. Did you try import telnetlib ? Note that in the code above I forgot the EOF, which is very much dependent of the equipment itself. You may have to write t.write('*IDN?\n') or t.write('IDN?\n\r') JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
Did you try import telnetlib ? Note that in the code above I forgot the EOF, which is very much dependent of the equipment itself. You may have to write t.write('*IDN?\n') or t.write('IDN?\n\r') JM Additionally, here's the code we're using for our signal generators, just to give you a broad idea: def getError(self): error = self._extractRsp(self._sendCmd('SYST:ERR?', 10)) if 'No error' in error: return None else: return error def _sendCmd(self, aCmd, timeout): self.send(str(aCmd) + self.SEND_LFCR) waitPattern = [self.PROMPT] try: index, _, rsp= self._telnet.expect(waitPattern, timeout) except EOFError: self._logger.error('Connection unexpectedly closed while sending/reading/ data.') raise MxgError('Connection unexpectedly closed while sending the command %s' % aCmd) if index == -1: raise MxgError('Timeout occurred while sendind the command %s' % aCmd) return rs def _extractRsp(self, rawRsp): # the returned string should be something like '\r\nresponse\r\nprompt' # or '\r\nprompt' # tries to extract the response only, removing the additional carriage returns and prompt rawRsp = rawRsp.replace(self.READ_LFCR+self.PROMPT, '') if rawRsp.startswith(self.READ_LFCR): rawRsp = rawRsp[2:] return rawRs -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Python, mySQL and password
Hi, ALL, Is there a way to make python script that connects to mySQL DB ask for a password on the: conn = mdb.connect(host, user) line. The host variable is localhost and the user variable is root (for developmental purposes). Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python, mySQL and password
Hello, On Mon, Dec 16, 2013 at 02:55:29AM -0800, Igor Korot wrote: Hi, ALL, Is there a way to make python script that connects to mySQL DB ask for a password on the: conn = mdb.connect(host, user) line. The host variable is localhost and the user variable is root (for developmental purposes). may be you think some like this: import MySQLdb dsn = { 'host': 127.0.0.1, 'user': root, 'passwd': , 'port': 3306, 'db': test } dsn['passwd'] = raw_input(Enter password for %s: % (dsn['user'])) mysql = MySQLdb.connect(**dsn) cursor = mysql.cursor(MySQLdb.cursors.DictCursor) but at this way the password what you type will showing! a. -- https://mail.python.org/mailman/listinfo/python-list
Packaging a private project
Dear List, What is the best way to distribute a private, pure python, Python 3 project that needs several modules (some available on pypi but some private and used by several separate projects) in order to run? I'd like to include everything that my project needs to run in a single package. The best way to do this seems to be to be to create symlinks to the source code of the 3rd party modules I need and create a setup.py file that includes them in its packages list. Is this what other people do? But even more ideally, I'd like to package my script and its dependencies in a single zip file that can be executed by python directly. I see several declarations that this is possible online, but I can't find a simple recipe for converting a script and its dependencies into this kind of distribution. Could someone give me a pointer to a description of the right way to do it. I'm making life harder for myself by using python 3 (PyInstaller still only supports Python 2) and by the fact that I can't release some of the necessary code publicly. Releasing modules and scripts on pypi has become very easy -- I'd forgotten how hard packaging private code is! Thank you for any help. N. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python, mySQL and password
Ervin Hegedüs wrote: Hello, On Mon, Dec 16, 2013 at 02:55:29AM -0800, Igor Korot wrote: Hi, ALL, Is there a way to make python script that connects to mySQL DB ask for a password on the: conn = mdb.connect(host, user) line. The host variable is localhost and the user variable is root (for developmental purposes). may be you think some like this: import MySQLdb dsn = { 'host': 127.0.0.1, 'user': root, 'passwd': , 'port': 3306, 'db': test } dsn['passwd'] = raw_input(Enter password for %s: % (dsn['user'])) mysql = MySQLdb.connect(**dsn) cursor = mysql.cursor(MySQLdb.cursors.DictCursor) but at this way the password what you type will showing! To avoid that use getpass.getpass() instead of raw_input(). http://docs.python.org/2/library/getpass.html -- https://mail.python.org/mailman/listinfo/python-list
Re: Launching Helium: A Selenium wrapper that makes web automation 50% easier
On Mon, Dec 16, 2013 at 5:17 AM, Michael Herrmann michael.herrm...@heliumhq.com wrote: Hi everyone, I'm working for a startup called BugFree Software and would like to announce that today we're launching our second product! Helium is a library that wraps around Selenium to simplify web automation. It does away with many of the technicalities involved with web scripting. For example: Here is a Selenium script. Can you guess what it does? ff = Firefox() ... text_area = ff.find_element_by_id(u_0_1q) text_area.send_keys(Hello World!) button = ff.find_element_by_class_name(_42g-) button.click() Here is the same script rewritten using Helium: start_firefox() ... write(Hello World!, into=Update Status) click(Post) Can you now guess what it does? That's right; It updates your Facebook status. In an extended comparison that we were invited to write for the December issue of Professional Tester (professionaltester.com), we found that an example script automating Gmail took 66% fewer lines of code and 75% less effort using Helium than with Selenium alone. You can find more information and download Helium from http://heliumhq.com. Any feedback would be highly appreciated. Hoping to hear your thoughts and comments, Is this open source? -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
Op maandag 16 december 2013 11:29:12 UTC+1 schreef Jean-Michel Pichavant: Such equipment often implements a telnet protocol. Have use try using the telnetlib module ? http://docs.python.org/2/library/telnetlib.html t = Telnet(host, port) t.write('*IDN?') print t.read_until('Whateverprompt') # you can use read_very_eager also JM Could you tell me how to install telnetlib on a linux-system (it's not available via apt-get install as I see it) kind regards, jean Please keep it on list, some other may have the same install issue or someone could have better insights on installing telnetlib. telnetlib is part of the standard modules in my Debian squeeze(python 2.5). Looking at the doc, it looks like it's available for python 3 as well. Strange that you don't have it. Did you try import telnetlib ? Note that in the code above I forgot the EOF, which is very much dependent of the equipment itself. You may have to write t.write('*IDN?\n') or t.write('IDN?\n\r') JM Here is the code: #!/usr/bin/env python import telnetlib host = '10.128.59.63' port = 7000 t = Telnet(host, port) t.write('*IDN?\n') print t.read_until('Whateverprompt') # you can use read_very_eager also and this is the result of executing the code(from which I deduce I have to install telnetlib, but how?) Traceback (most recent call last): File ./nctelnet.py, line 5, in module t = Telnet(host, port) NameError: name 'Telnet' is not defined kind regards, jean -- https://mail.python.org/mailman/listinfo/python-list
Re: Python, mySQL and password
Hello Peter, On Mon, Dec 16, 2013 at 12:38:33PM +0100, Peter Otten wrote: Ervin Hegedüs wrote: dsn['passwd'] = raw_input(Enter password for %s: % (dsn['user'])) [...] but at this way the password what you type will showing! To avoid that use getpass.getpass() instead of raw_input(). http://docs.python.org/2/library/getpass.html well, thanks a lot :) a. -- https://mail.python.org/mailman/listinfo/python-list
Question RE urllib
So I'm using the following script to check our sites to make sure they are all up and some of them are reporting they are down when, in fact, they are actually up. These sites do not require a logon in order for the home page to come up. Could this be due to some port being blocked internally ? Only one of the sites reporting as down is https but all are internal sites. Is there some other component I should be including in the script ? There are about 30 or 40 sites that I have listed in all. I just use those in the following script as examples. Thanks import urllib sites = [http://www.amazon.com/;, https://internalsite.com/intranet.html;, etc.] for site in sites: try: urllib.urlopen(site) print site + except Exception, e: print site + is down -- https://mail.python.org/mailman/listinfo/python-list
Re: Question RE urllib
On Mon, Dec 16, 2013 at 6:40 AM, Jeff James j...@jeffljames.com wrote: So I'm using the following script to check our sites to make sure they are all up and some of them are reporting they are down when, in fact, they are actually up. These sites do not require a logon in order for the home page to come up. Could this be due to some port being blocked internally ? Only one of the sites reporting as down is https but all are internal sites. Is there some other component I should be including in the script ? There are about 30 or 40 sites that I have listed in all. I just use those in the following script as examples. Thanks import urllib sites = [http://www.amazon.com/;, https://internalsite.com/intranet.html;, etc.] for site in sites: try: urllib.urlopen(site) print site + except Exception, e: print site + is down In the handler print out the exception you are getting. -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On Mon, Dec 16, 2013 at 8:42 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: I've done the latter, but still can't fit all the data for my 100+ screens into a one liner, help please :) With 100 screens, you should be able to use lines of text up to 8000 characters long - just make sure your screens are organized horizontally. Shorten all variable names to a single letter, omit all unnecessary spaces, and you should be able to fit the code within that space. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Question RE urllib
On 2013-12-16 04:40, Jeff James wrote: These sites do not require a logon in order for the home page to come up. Could this be due to some port being blocked internally ? Only one of the sites reporting as down is https but all are internal sites. Is there some other component I should be including in the script ? From your description, I'm unsure whether it's *only* the HTTPS sites that are having issues, or a subset of your URL list that includes both HTTP and HTTPS (where those sites happen to be internal). Either way, my first suspicion is that you have some sort of proxy server in your network that web-browsers use. The urlopen() accepts a parameter to list proxy server information, which you should be able to glean from your browser settings. If your web-browser isn't using a proxy, the sites might be doing unsavory things like filtering by user-agent. Dumping the contents of the exception (and including it here) might help diagnose. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
Here is the code: #!/usr/bin/env python import telnetlib host = '10.128.59.63' port = 7000 t = Telnet(host, port) t.write('*IDN?\n') print t.read_until('Whateverprompt') # you can use read_very_eager also and this is the result of executing the code(from which I deduce I have to install telnetlib, but how?) Traceback (most recent call last): File ./nctelnet.py, line 5, in module t = Telnet(host, port) NameError: name 'Telnet' is not defined kind regards, jean t = telnetlib.Telnet(host, port) JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: min max from tuples in list
On Sun, Dec 15, 2013 at 2:41 PM, Tim Roberts t...@probo.com wrote: Dennis Lee Bieber wlfr...@ix.netcom.com wrote: Well performant is performant enough for the purposes of communicating on the python list I think :D Most probably could figure it out as being stylistically similar to conformant, which I believe IS used in English G conformant = something that conforms performant = something that performs Yes, I suspect it comes from people expecting too much consistency. If something that has conformance is conformant, then something that has good performance must be performant. In a surprising coincidence, the word performant came up in a Daily MTG article today: http://www.wizards.com/Magic/Magazine/Article.aspx?x=mtg/daily/feature/278 Though it is used in double quotes to indicate that it's not exactly standard English :) Funny to see two nerdy interests meet! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
On Friday, December 13, 2013 5:58:49 AM UTC+8, Chris Angelico wrote: On Fri, Dec 13, 2013 at 8:27 AM, Dan Stromberg drsali...@gmail.com wrote: On Thu, Dec 12, 2013 at 6:16 AM, Grant Edwards invalid@invalid.invalid wrote: Sockets reserve the right to split one socket.send() into multiple socket.recv()'s on the other end of the communication, or to aggregate multiple socket.send()'s into a single socket.recv() - pretty much any way the relevant IP stacks and communications equipment feel like for the sake of performance or reliability. Just to be pedantic: _TCP_ sockets reserver that right. UDP sockets do not, and do in fact guarantee that each message is discrete. [It appears that the OP is undoubtedly using TCP sockets.] I haven't done a lot of UDP, but are you pretty sure UDP can't at least fragment large packets? What's a router or switch to do if the Path MTU isn't large enough for an original packet? http://www.gamedev.net/topic/343577-fragmented-udp-packets/ I'm no expert on this (mostly I do TCP, or UDP with fairly small packets), but the packet should be reassembled at the far end. When your application comes to receive it, it'll receive the entire UDP packet as a whole. UDP fragmentation has several problems. First, if any fragment is lost, it won't be retransmitted (as TCP will), so the whole datagram is lost. And secondly, if you stream data across the network in a series of packets just a little too large to fit, each one will get split in two and you'll end up with twice as many packets going out, ergo abysmal performance. With TCP, there's the chance that the sender and receiver can between them figure out what packet size to use (cf path MTU discovery), but that won't happen with UDP unless the application consciously does it. So it's something to be cautious of in terms of performance, but if you want to send large UDP packets because they make sense, just go ahead and do it. Now, if you want reliability AND datagrams, it's a lot easier to add boundaries to a TCP stream (sentinel or length prefixes) than to add reliability to UDP... ChrisA It is trivial to use UDP with forward error correction such as the CD in 1982. -- https://mail.python.org/mailman/listinfo/python-list
Re: Wrapping around a list in Python.
On Mon, Dec 16, 2013 at 12:26 AM, shengjie.sheng...@live.com wrote: The idea is to grab the last 4 elements of the array. However i have an array that contains a few hundred elements in it. And the values continues to .append over time. How would i be able to display the last 4 elements of the array under such a condition? I assume you mean 'list' rather than 'array'. If all you want to do is 'display' the last 4 elements: big_list = [0,1,2,3,4,5,6,7,8,9] last4 = big_list[-4:] print(last4) -- https://mail.python.org/mailman/listinfo/python-list
Re: Wrapping around a list in Python.
On Sun, 15 Dec 2013 21:26:49 -0800 (PST), shengjie.sheng...@live.com wrote: The idea is to grab the last 4 elements of the array. However i have an array that contains a few hundred elements in it. And the values continues to .append over time. How would i be able to display the last 4 elements of the array under such a condition? Your earlier example showed [5, 4, 1, 2] as one of the results, which is not the last four. But assuming your goal has now changed and you really have an array (or list) of a few hundred elements, then you can just use data [-4:] to get them. But if you're being imprecise and these values are not really in an array, then follow Peter ' advice and use a deque. Or fake it with a list, appending to the end and popping from the beginning. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
On Mon, Dec 16, 2013 at 11:38 PM, 8 Dihedral dihedral88...@gmail.com wrote: It is trivial to use UDP with forward error correction such as the CD in 1982. This is another reason for moving to IPv6. With IPv4, the size of a datagram is limited to 64KB, but with IPv6, you could carry an entire CD's contents in a single message. You could not carry a DVD, though, so Dihedral is quite correct to cite the CD here. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Question Re urllib (Jeff James)
I'm not really receiving an exception other than those three sites, out of the 30 or so I have listed, are the only sites which show is down at the end of that line specifying the site. Where # has been substituted for our domain name https://my..com/intranet.html* is down* http://#.main..com/psso/pssignsso.asp?dbname=FSPRD90 * is down* http://sharepoint..com/regions/west/PHX_NSC/default.aspx * is down* Cc: python-list@python.org Date: Mon, 16 Dec 2013 06:54:48 -0500 Subject: Re: Question RE urllib On Mon, Dec 16, 2013 at 6:40 AM, Jeff James j...@jeffljames.com wrote: So I'm using the following script to check our sites to make sure they are all up and some of them are reporting they are down when, in fact, they are actually up. These sites do not require a logon in order for the home page to come up. Could this be due to some port being blocked internally ? Only one of the sites reporting as down is https but all are internal sites. Is there some other component I should be including in the script ? There are about 30 or 40 sites that I have listed in all. I just use those in the following script as examples. Thanks import urllib sites = [http://www.amazon.com/;, https://internalsite.com/intranet.html , etc.] for site in sites: try: urllib.urlopen(site) print site + except Exception, e: print site + is down In the handler print out the exception you are getting. -- https://mail.python.org/mailman/listinfo/python-list
Re: Launching Helium: A Selenium wrapper that makes web automation 50% easier
On Monday, December 16, 2013 12:40:56 PM UTC+1, larry@gmail.com wrote: ... Is this open source? No. We quit our daytime jobs to work on this project and need the income to sustain our development... -- https://mail.python.org/mailman/listinfo/python-list
Re: Question Re urllib (Jeff James)
On Monday, December 16, 2013, Jeff James wrote: I'm not really receiving an exception other than those three sites, out of the 30 or so I have listed, are the only sites which show is down at the end of that line specifying the site. Where # has been substituted for our domain name https://my..com/intranet.html* is down* http://#.main..com/psso/pssignsso.asp?dbname=FSPRD90 * is down * http://sharepoint..com/regions/west/PHX_NSC/default.aspx * is down* Cc: python-list@python.org javascript:_e({}, 'cvml', 'python-list@python.org'); Date: Mon, 16 Dec 2013 06:54:48 -0500 Subject: Re: Question RE urllib On Mon, Dec 16, 2013 at 6:40 AM, Jeff James j...@jeffljames.comjavascript:_e({}, 'cvml', 'j...@jeffljames.com'); wrote: So I'm using the following script to check our sites to make sure they are all up and some of them are reporting they are down when, in fact, they are actually up. These sites do not require a logon in order for the home page to come up. Could this be due to some port being blocked internally ? Only one of the sites reporting as down is https but all are internal sites. Is there some other component I should be including in the script ? There are about 30 or 40 sites that I have listed in all. I just use those in the following script as examples. Thanks import urllib sites = [http://www.amazon.com/;, https://internalsite.com/intranet.html;, etc.] for site in sites: try: urllib.urlopen(site) print site + except Exception, e: print site + is down In the handler print out the exception you are getting. If your exception handler is being called then you are indeed getting an exception. Add: print str(e) to the handler -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
Op maandag 16 december 2013 13:05:41 UTC+1 schreef Jean-Michel Pichavant: Here is the code: #!/usr/bin/env python import telnetlib host = '10.128.59.63' port = 7000 t = Telnet(host, port) t.write('*IDN?\n') print t.read_until('Whateverprompt') # you can use read_very_eager also and this is the result of executing the code(from which I deduce I have to install telnetlib, but how?) Traceback (most recent call last): File ./nctelnet.py, line 5, in module t = Telnet(host, port) NameError: name 'Telnet' is not defined kind regards, jean t = telnetlib.Telnet(host, port) this helps, but I don't know what to do with print t.read_until('Whateverprompt') should I send CTRL-ALT-ALTGR-] after some time? kind regards, jean -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On 16/12/2013 11:58, Chris Angelico wrote: On Mon, Dec 16, 2013 at 8:42 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: I've done the latter, but still can't fit all the data for my 100+ screens into a one liner, help please :) With 100 screens, you should be able to use lines of text up to 8000 characters long - just make sure your screens are organized horizontally. Shorten all variable names to a single letter, omit all unnecessary spaces, and you should be able to fit the code within that space. ChrisA Thanks for this extremely useful advice, it's much appreciated :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
On Friday, December 13, 2013 5:58:49 AM UTC+8, Chris Angelico wrote: Now, if you want reliability AND datagrams, it's a lot easier to add boundaries to a TCP stream (sentinel or length prefixes) than to add reliability to UDP... In article 11cb8cd3-7a12-46b2-abc6-53fbc2a54...@googlegroups.com, 8 Dihedral dihedral88...@gmail.com wrote: It is trivial to use UDP with forward error correction such as the CD in 1982. CD uses Reed-Solomon coding, which is great for correcting the types of errors expected on a CD. Namely, bursts of bit errors caused by localized failure of the optical coating, scratches, dirt, etc. It wouldn't be hard to build something like that on top of UDP, but those sorts of errors are not what you typically see in networks. It's relatively rare for a bit to get corrupted in a network packet. And, when it does, it's almost certainly caught by lower-level mechanisms such as ethernet frame CRC. Much more likely is for a packet to get dropped because of queue overflow, or for sequential packets to arrive out of order due to multiple transmission paths with different latencies. Those are the sorts of things TCP protects against. Sure, you could implement retransmit timers and packet reordering in user code, but it would be distinctly non-trivial and ultimately you would end up reinventing most of TCP. Except that your implementation would suck compared to the kernel algorithms which have been continuously tested and fine-tuned for the past 30 years. -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
- Original Message - Op maandag 16 december 2013 13:05:41 UTC+1 schreef Jean-Michel Pichavant: Here is the code: #!/usr/bin/env python import telnetlib host = '10.128.59.63' port = 7000 t = Telnet(host, port) t.write('*IDN?\n') print t.read_until('Whateverprompt') # you can use read_very_eager also and this is the result of executing the code(from which I deduce I have to install telnetlib, but how?) Traceback (most recent call last): File ./nctelnet.py, line 5, in module t = Telnet(host, port) NameError: name 'Telnet' is not defined kind regards, jean t = telnetlib.Telnet(host, port) this helps, but I don't know what to do with print t.read_until('Whateverprompt') should I send CTRL-ALT-ALTGR-] after some time? kind regards, jean one way to approach the problem is to first make some monkey tests. 1/ connect to your equipment using telnet (from the linux shell) 2/ try typing some commands like *IDN? 3/ see how the equipment is answering 4/ you need to identify what is the prompt, and what EndOfLine sequence is used. 5/ then in a python shell, try to reproduce the behavior: import telnetlib t = telnetlib.Telnet(host, port) t.read_very_eager() #flush t.write('\n') prompt = t.read_very_eager() #this is one way to get the prompt print repr(prompt) #you may identify the EOL sequence with this one When you get a good feeling about how it works, write the code. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Downloading multiple files based on info extracted from CSV
On Thursday, December 12, 2013 5:20:59 PM UTC-5, Chris Angelico wrote: import urllib import csv # You actually could get away with not using a with # block here, but may as well keep it for best practice with open('clients.csv') as f: for client in csv.reader(f): urllib.urlretrieve(client[7], client[0] + .csv) Yep, that's it! That's all you need. Worked perfect. Thank you! -- https://mail.python.org/mailman/listinfo/python-list
Small script to check serial port sucking down system resources.
i am new to python and programming all together. i wrote a program to watch a serial port and look for a command. then send a tcp packet. all works great but it takes my processor load to about %25. not sure if there is a way to make this more efficient. import serial import socket HOST = '127.0.0.1'# The remote host PORT = 5250 # The same port as used by the server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) ## ser = serial.Serial( port='COM10',\ baudrate=9600,\ parity=serial.PARITY_NONE,\ stopbits=serial.STOPBITS_ONE,\ bytesize=serial.EIGHTBITS,\ timeout=0) print(connected to: + ser.portstr) #this will store the line line = [] c = 0 while True: for c in ser.readline(): line.append(c) if c == '1': s.send('CG 1-21 ADD 1 reserveisoff 1 \r\n') data = s.recv(1024) print 'Received', repr(data) print(one) line = [] break if c == '2': s.send('PLAY 1-1 AMB.mp4 \r\n') data = s.recv(1024) print 'Received', repr(data) s.send('LOADBG 1-1 EMPTY MIX 30 AUTO \r\n') data = s.recv(1024) print 'Received', repr(data) print(two) line = [] break s.close() ser.close() -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On 12/15/13, 5:06 PM, Chris Angelico wrote: Yeah, but there's a difference between passing your GUI incantations on to a library function (written in C but now just part of a binary library) and feeding them to a completely different language interpreter. When I write something with PyGTK, I can't, even in theory, give it arbitrary C code to execute. From what I understand here, that *is* true of Tcl, which means that the Python download contains a Python interpreter and a Tcl interpreter. I'm not saying that's a bad thing to do, but it is calculated to provoke remark. Yes, a Tkinter app has both a Python interpreter and an underlying Tcl interpreter. Let's be clear about that. The technical reason for this is that, during Python's early development, Tk was the simplest, most powerful and OSS-friendly GUI toolkit out there (compared to, let's say, Motif). Its reliance on Tcl was a plus because Tcl's C API is exceptionally clean and easy to embed/call from other C libraries (that was Tcl's original main focus, embedding in C). Embedding the Tcl interpreter remains a sound decision today. It makes it trivial to keep Tkinter updated in sync with Tk updates, since the Tcl interpreter does most of the heavy lifting. The recent effort to wrap Tk's new themed widgets is a good one: nearly all of the work was done at the Python level. Compare this approach to Perl's original one, which stripped out Tcl and implemented Tk integration entirely in C. Any updates require heavy lifting in C and, in fact, Perl/Tk has not kept up with Tk's main line of development (it does not run natively on the Mac, for instance). Calling through Tkinter to Tcl also provides some other conveniences. If you're writing a Tkinter app and want to access some platform-specific functionality that requires C calls, that may require a library extension written against Tcl/Tk's C API (i.e. the Mac's NSServices API--that can't be accessed using ctypes because it hooks into the window server). Fortunately, Tk is very easy to extend in C--much simpler than extending wxWidgets or Qt. Finally, Tcl is itself a fully-featured, general programming language that is a peer to Python both generationally and in terms of its capabilities; the main way it lags is in the size of its development community. In other words, you are not handing the ball off to a 90-pound weakling if you need to call into Tcl from Python via Tkinter. ;-) --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
On 12/16/13 3:02 AM, Mark wrote: If i just try to double click the script, i get an index error, i can barely see the window it disappears so fast, but thats what I see. If you're going to participate in this forum, you'll get better help from people if you use the medium well. 1) Sending 4 message in a row, within 15 minutes, each replying to the other, is not a good way to use a forum like this. Get your thoughts in order and send one message. 2) While I am normally quite tolerant of the double-spacing Google Groups insists on, your messages are taking it to absurd extremes. Take a look at your last message: https://mail.python.org/pipermail/python-list/2013-December/662678.html True, it's kind of beautiful in an abstract way, and is an interesting demonstration of certain binary behaviors, but it is not a good way to participate here. Of course, the messages you post are your choice, but you should consider the effect they have on the people you are hoping to get help from. -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
Op maandag 16 december 2013 15:16:17 UTC+1 schreef Jean-Michel Pichavant: - Original Message - Op maandag 16 december 2013 13:05:41 UTC+1 schreef Jean-Michel Pichavant: Here is the code: #!/usr/bin/env python import telnetlib host = '10.128.59.63' port = 7000 t = Telnet(host, port) t.write('*IDN?\n') print t.read_until('Whateverprompt') # you can use read_very_eager also and this is the result of executing the code(from which I deduce I have to install telnetlib, but how?) Traceback (most recent call last): File ./nctelnet.py, line 5, in module t = Telnet(host, port) NameError: name 'Telnet' is not defined kind regards, jean t = telnetlib.Telnet(host, port) this helps, but I don't know what to do with print t.read_until('Whateverprompt') should I send CTRL-ALT-ALTGR-] after some time? kind regards, jean one way to approach the problem is to first make some monkey tests. 1/ connect to your equipment using telnet (from the linux shell) 2/ try typing some commands like *IDN? 3/ see how the equipment is answering 4/ you need to identify what is the prompt, and what EndOfLine sequence is used. 5/ then in a python shell, try to reproduce the behavior: import telnetlib t = telnetlib.Telnet(host, port) t.read_very_eager() #flush t.write('\n') prompt = t.read_very_eager() #this is one way to get the prompt print repr(prompt) #you may identify the EOL sequence with this one When you get a good feeling about how it works, write the code. Running you code I get as response: '' This is what I got using telnet: [jean:~] $ telnet 10.128.59.63 7000 Trying 10.128.59.63... Connected to 10.128.59.63. Escape character is '^]'. *IDN? KEITHLEY INSTRUMENTS INC.,MODEL 2425,1078209,C32 Oct 4 2010 14:20:11/A02 /E/ H after pressing CTRL-ALT-ALTGR-] I get this: ^[^] after which I get the telnet-prompt telnet and I can quit telnet by entering quit kind regards, jean -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On Tue, Dec 17, 2013 at 1:55 AM, Kevin Walzer k...@codebykevin.com wrote: Finally, Tcl is itself a fully-featured, general programming language that is a peer to Python both generationally and in terms of its capabilities; the main way it lags is in the size of its development community. In other words, you are not handing the ball off to a 90-pound weakling if you need to call into Tcl from Python via Tkinter. ;-) Having made a tweak to gitk at one point, I have to say Tcl is definitely inferior to Python. I'd much rather work with Python itself. :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On 12/16/13, 10:20 AM, Chris Angelico wrote: Having made a tweak to gitk at one point, I have to say Tcl is definitely inferior to Python. Without starting a flame war, can you elaborate? I'm curious about your perspective. (I studied PSL--Python as a Second Language--so develop in it with a slight accent. I'm a native Tcl developer, for better or worse.) --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com -- https://mail.python.org/mailman/listinfo/python-list
Re: min max from tuples in list
On Sunday, December 15, 2013 9:11:15 AM UTC+5:30, Tim Roberts wrote: Dennis Lee Bieber wrote: Well performant is performant enough for the purposes of communicating on the python list I think :D Most probably could figure it out as being stylistically similar to conformant = something that conforms performant = something that performs Yes, I suspect it comes from people expecting too much consistency. If something that has conformance is conformant, then something that has good performance must be performant. And things that have consistency are of course... consistant (not consistent) -- https://mail.python.org/mailman/listinfo/python-list
Re: min max from tuples in list
On 12/16/13 10:49 AM, rusi wrote: On Sunday, December 15, 2013 9:11:15 AM UTC+5:30, Tim Roberts wrote: Dennis Lee Bieber wrote: Well performant is performant enough for the purposes of communicating on the python list I think :D Most probably could figure it out as being stylistically similar to conformant = something that conforms performant = something that performs Yes, I suspect it comes from people expecting too much consistency. If something that has conformance is conformant, then something that has good performance must be performant. And things that have consistency are of course... consistant (not consistent) In English, it's spelled consistent: http://en.wiktionary.org/wiki/consistant -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On Tue, Dec 17, 2013 at 2:32 AM, Kevin Walzer k...@codebykevin.com wrote: On 12/16/13, 10:20 AM, Chris Angelico wrote: Having made a tweak to gitk at one point, I have to say Tcl is definitely inferior to Python. Without starting a flame war, can you elaborate? I'm curious about your perspective. (I studied PSL--Python as a Second Language--so develop in it with a slight accent. I'm a native Tcl developer, for better or worse.) Here's the Tcl procedure that I tweaked. This is from gitk; I find the word diff not all that useful, but a character diff at times is very useful. I haven't found a way to configure the word diff regex through gitk's options, so I tweaked it in the source code. proc getblobdiffs {ids} { global blobdifffd diffids env global diffinhdr treediffs global diffcontext global ignorespace global worddiff global limitdiffs vfilelimit curview global diffencoding targetline diffnparents global git_version currdiffsubmod set textconv {} if {[package vcompare $git_version 1.6.1] = 0} { set textconv --textconv } set submodule {} if {[package vcompare $git_version 1.6.6] = 0} { set submodule --submodule } set cmd [diffcmd $ids -p $textconv $submodule -C --cc --no-commit-id -U$diffcontext] if {$ignorespace} { append cmd -w } if {$worddiff ne [mc Line diff]} { append cmd --word-diff=porcelain --word-diff-regex=. } if {$limitdiffs $vfilelimit($curview) ne {}} { set cmd [concat $cmd -- $vfilelimit($curview)] } if {[catch {set bdf [open $cmd r]} err]} { error_popup [mc Error getting diffs: %s $err] return } set targetline {} set diffnparents 0 set diffinhdr 0 set diffencoding [get_path_encoding {}] fconfigure $bdf -blocking 0 -encoding binary -eofchar {} set blobdifffd($ids) $bdf set currdiffsubmod filerun $bdf [list getblobdiffline $bdf $diffids] } First off, everything's done with commands, rather than assignment (set diffinhdr 0), which is very shell-style and not very programming-style. Can live with that, though even shells can use equals signs for simplicity. Similarly, the shell style of adorning variable usage feels messy. There are string literals, some of which contain interpolated variables; there are dollar-sign adorned variables; and then there are other words. What are the other words? Are they implicit strings (as they would be in, say, bash)? I've never really liked that style. Anyway. Can get past that. Secondly, what does this do? if {$worddiff ne [mc Line diff]} I *think* it means 'if $worddiff is not equal to Line diff (this code is executed for the options Markup words and Color words, but what's the mc do? How am I supposed to figure out what it does? Where do I begin to look? This is where, IMO, Python tends to be a lot clearer. It's easy to see what's an object and what's a method on it, and every bare word is either a local name or a standard built-in name. I'm sure Tcl's a great language, but I'd rather not have to drop out of Python into it if I can help it. :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On Saturday, December 14, 2013 8:12:16 PM UTC+8, Jai wrote: GUI:-want to learn GUI programming in python , how should i proceed. There are lots of book here so I am confuse which book i should refer so that i don't waste time . please answer Please check JYTHON and those ready-for-novice GUI tools in java. Python is a higher level language that can support manny lower level languages. -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
This is what I got using telnet: [jean:~] $ telnet 10.128.59.63 7000 Trying 10.128.59.63... Connected to 10.128.59.63. Escape character is '^]'. *IDN? KEITHLEY INSTRUMENTS INC.,MODEL 2425,1078209,C32 Oct 4 2010 14:20:11/A02 /E/ H after pressing CTRL-ALT-ALTGR-] I get this: ^[^] after which I get the telnet-prompt telnet and I can quit telnet by entering quit kind regards, jean -- https://mail.python.org/mailman/listinfo/python-list Looks like you don't have any prompt. Try something simple first: import telnetlib host = '10.128.59.63' port = 7000 t = Telnet(host, port) def flush() t.read_very_eager() def sendCmd(cmd) t.write('%s\n' % cmd) return flush() flush() print sendCmd('*IDN?') print sendCmd('*OPC?') JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On 2013-12-16, Chris Angelico ros...@gmail.com wrote: On Tue, Dec 17, 2013 at 2:32 AM, Kevin Walzer k...@codebykevin.com wrote: On 12/16/13, 10:20 AM, Chris Angelico wrote: Having made a tweak to gitk at one point, I have to say Tcl is definitely inferior to Python. Without starting a flame war, can you elaborate? I'm curious about your perspective. I wrote a few Tcl apps once many, many years ago. After attempting to write something more than a few hundred lines long, I gave up and swore off Tcl completely. I switched to Scheme, and later to Python. The things I found infuriating about Tcl: * The everything is a string view of the world is severly limiting if you're not just processing strings. * The quoting syntax and semantics appears to have been invented by somebody at the CIA as a way to torture programmers into doing... something... I don't know what. * Tcl doesn't seem to have any sort of coherent design or philosophy behind it but rather consists of a bunch of hacks piled on top of a simple and limited shell-like string processing language. It sort of feels like PHP in that regard. When I finally gave up fighting with Tcl's quoting semantics half way through a medium/small application and switched to Scheme/Tk, I had my app written from scratch in a fraction of the time it took to get about half way done in Tcl, and with about 1/3 the lines of code. Python probably would have cut both hours and lines by half again compared to Scheme. -- Grant Edwards grant.b.edwardsYow! I'd like some JUNK at FOOD ... and then I want to gmail.combe ALONE -- -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On Tue, Dec 17, 2013 at 3:46 AM, Grant Edwards invalid@invalid.invalid wrote: * The everything is a string view of the world is severly limiting if you're not just processing strings. I wasn't sure if that was the case, from what I was seeing. Are there any aggregate types at all? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On 2013-12-16, Chris Angelico ros...@gmail.com wrote: On Tue, Dec 17, 2013 at 3:46 AM, Grant Edwards invalid@invalid.invalid wrote: * The everything is a string view of the world is severly limiting if you're not just processing strings. I wasn't sure if that was the case, from what I was seeing. Are there any aggregate types at all? There are arrays with string keys (similar to Python dictionaries). -- Grant Edwards grant.b.edwardsYow! hubub, hubub, HUBUB, at hubub, hubub, hubub, HUBUB, gmail.comhubub, hubub, hubub. -- https://mail.python.org/mailman/listinfo/python-list
Concatenate string list to number list to form title - Logic needed.
Hi, I'm completely new to python. I just need simple logic to get output without any loops. I have list of string and list of list of numbers. Each string should be concatenated with every third and fourth values to generate proper titles in list of strings. t = ['Start','End'] a = [[1,2,3,4], [5,6,7,8]] Expected Result : ( list of strings ) ['Start - 3 , End - 4', 'Start - 7 , End - 8'] Note : First 2 values from each list should be ignored. Could anyone please guide me with best solution without loops ? Thanks Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: Concatenate string list to number list to form title - Logic needed.
On Tue, Dec 17, 2013 at 4:16 AM, Ravi Prabakaran ravi@gmail.com wrote: Could anyone please guide me with best solution without loops ? Why without loops? The best solution, in my opinion, is a loop. Is this a specific challenge (homework)? I could make you a list comprehension, but that's really just another form of loop More information on the problem parameters, please? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Determining whether a glyph is available in Tkinter
I have a Tkinter app that can optionally label some buttons with certain Unicode glyphs that aren't always available (depending on the OS, etc.). When they aren't available, Tkinter renders them as \u. What I'd like to do is check whether the glyphs are available, and fall back to my own alternate text for the button if not. Can I do this? I'd also like to do the same in pygtk. -- https://mail.python.org/mailman/listinfo/python-list
Re: Concatenate string list to number list to form title - Logic needed.
On 16/12/2013 17:16, Ravi Prabakaran wrote: Hi, I'm completely new to python. I just need simple logic to get output without any loops. I have list of string and list of list of numbers. Each string should be concatenated with every third and fourth values to generate proper titles in list of strings. t = ['Start','End'] a = [[1,2,3,4], [5,6,7,8]] Expected Result : ( list of strings ) ['Start - 3 , End - 4', 'Start - 7 , End - 8'] Note : First 2 values from each list should be ignored. Could anyone please guide me with best solution without loops ? Thanks Ravi I've no idea what your definition of best is but this works. strings = ['{} - {} , {} - {}'.format(t[0], b[-2], t[1], b[-1]) for b in a] -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Concatenate string list to number list to form title - Logic needed.
On Tue, Dec 17, 2013 at 4:41 AM, Ravi Prabakaran ravi@gmail.com wrote: Hi Chris, Thanks for reply. If you have any good idea with loop, please post. But i'm looking same without loop because python has slicing,concatenating and other straight forward feature. I guess it can be done without loop. My client does not prefer loops and expects simple and neat code to improve performance. We are dealing with billion data. I'm going to hope that it was in error that you sent this off-list, or at least that you won't mind my replying on-list. Here's one way to do it: t = ['Start','End'] a = [[1,2,3,4], [5,6,7,8]] result = [] for cur in a: result.append(%s - %d%(t[0],cur[2])) result.append(%s - %d%(t[1],cur[3])) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Concatenate string list to number list to form title - Logic needed.
On Tue, Dec 17, 2013 at 4:51 AM, Chris Angelico ros...@gmail.com wrote: t = ['Start','End'] a = [[1,2,3,4], [5,6,7,8]] result = [] for cur in a: result.append(%s - %d%(t[0],cur[2])) result.append(%s - %d%(t[1],cur[3])) Whoops, I misread the desired output, I thought you wanted a four-string list. It's two strings. That's actually easier, and Mark's solution is pretty much what I'd go for. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Concatenate string list to number list to form title - Logic needed.
Ravi Prabakaran writes: I'm completely new to python. I just need simple logic to get output without any loops. I have list of string and list of list of numbers. Each string should be concatenated with every third and fourth values to generate proper titles in list of strings. t = ['Start','End'] a = [[1,2,3,4], [5,6,7,8]] Expected Result : ( list of strings ) ['Start - 3 , End - 4', 'Start - 7 , End - 8'] Note : First 2 values from each list should be ignored. Could anyone please guide me with best solution without loops ? That's a strange requirement - to have repetition without loops, in Python, and still have a best solution. I suppose it's fine to have a (built-in) function do the looping for you so that there is no explicit loop in your own code. The .format method of Python strings can do each individual string: list(map('{2} - {0} , {3} - {1}' .format('{0[2]}', '{0[3]}', *t) .format, a)) The first (inner) call of .format builds the actual format string whose .format method then builds each output string: {0[2]} in a format string refers to the argument position 0 and its element position 2; *t spreads the two elements of t as further positional arguments. If you have any background in functional programming with lists, map should be fine and familiar. I would probably build and name the format string outside the actual call as follows (untested). start, end = t format = ( '{2} - {0} , {3} - {1}' .format('{0[2]}', '{0[3]}', start, end) .format ) list(map(format, a)) All other things that come to mind would either be too much like loops or they couldn't possibly be a best solution. Incidentally, if you want a one-liner and tolerate long lines, the first form I gave is perfectly good for that purpose. I think *t and str.format require version 3 of Python. -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
Op maandag 16 december 2013 17:44:31 UTC+1 schreef Jean-Michel Pichavant: This is what I got using telnet: [jean:~] $ telnet 10.128.59.63 7000 Trying 10.128.59.63... Connected to 10.128.59.63. Escape character is '^]'. *IDN? KEITHLEY INSTRUMENTS INC.,MODEL 2425,1078209,C32 Oct 4 2010 14:20:11/A02 /E/ H after pressing CTRL-ALT-ALTGR-] I get this: ^[^] after which I get the telnet-prompt telnet and I can quit telnet by entering quit kind regards, jean -- https://mail.python.org/mailman/listinfo/python-list Looks like you don't have any prompt. Try something simple first: import telnetlib host = '10.128.59.63' port = 7000 t = Telnet(host, port) def flush() t.read_very_eager() def sendCmd(cmd) t.write('%s\n' % cmd) return flush() flush() print sendCmd('*IDN?') print sendCmd('*OPC?') Still no success: jean@mantec:~$ ./test.py File ./test.py, line 7 def flush() ^ SyntaxError: invalid syntax Tried it both with python2 and python3, same error... kind regards, jean -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
On Tue, Dec 17, 2013 at 5:26 AM, Jean Dubois jeandubois...@gmail.com wrote: Try something simple first: import telnetlib host = '10.128.59.63' port = 7000 t = Telnet(host, port) def flush() t.read_very_eager() def sendCmd(cmd) t.write('%s\n' % cmd) return flush() flush() print sendCmd('*IDN?') print sendCmd('*OPC?') Still no success: jean@mantec:~$ ./test.py File ./test.py, line 7 def flush() ^ SyntaxError: invalid syntax Tried it both with python2 and python3, same error... Folks, the OP isn't an expert. Please test your scripts before posting! I don't have everything I need to test this fully, but here's a variant of the above that's at least syntactically correct: from telnetlib import * host = '10.128.59.63' port = 7000 t = Telnet(host, port) def flush(): t.read_very_eager() def sendCmd(cmd): t.write('%s\n' % cmd) return flush() flush() print sendCmd('*IDN?') print sendCmd('*OPC?') It's written for Python 2, so use that interpreter. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Concatenate string list to number list to form title - Logic needed.
Jussi Piitulainen wrote: Ravi Prabakaran writes: I'm completely new to python. I just need simple logic to get output without any loops. I have list of string and list of list of numbers. Each string should be concatenated with every third and fourth values to generate proper titles in list of strings. t = ['Start','End'] a = [[1,2,3,4], [5,6,7,8]] Expected Result : ( list of strings ) ['Start - 3 , End - 4', 'Start - 7 , End - 8'] Note : First 2 values from each list should be ignored. Could anyone please guide me with best solution without loops ? That's a strange requirement - to have repetition without loops, in Python, and still have a best solution. I suppose it's fine to have a (built-in) function do the looping for you so that there is no explicit loop in your own code. The .format method of Python strings can do each individual string: list(map('{2} - {0} , {3} - {1}' .format('{0[2]}', '{0[3]}', *t) .format, a)) Don't do that if t may contain user data. For the sake of the argument let's assume that a[...][0:2] is confidential. Then t = {0[0]}, {0[1]} list(map('{2} - {0} , {3} - {1}' ... .format('{0[2]}', '{0[3]}', *t) ... .format, a)) ['1 - 3 , 2 - 4', '5 - 7 , 6 - 8'] (I think doubling the braces is sufficient to fix this) The first (inner) call of .format builds the actual format string whose .format method then builds each output string: {0[2]} in a format string refers to the argument position 0 and its element position 2; *t spreads the two elements of t as further positional arguments. -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
On Mon, 16 Dec 2013 10:26:14 -0800 (PST), Jean Dubois jeandubois...@gmail.com wrote: File ./test.py, line 7 def flush() ^ SyntaxError: invalid syntax A definition line needs to end with a colon (fix the other as well) -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Concatenate string list to number list to form title - Logic needed.
In 2333bfb4-cd72-4ed0-9b28-d8dbe26b5...@googlegroups.com Ravi Prabakaran ravi@gmail.com writes: Hi, I'm completely new to python. I just need simple logic to get output without any loops. I have list of string and list of list of numbers. Each string should be concatenated with every third and fourth values to generate proper titles in list of strings. t = ['Start','End'] a = [[1,2,3,4], [5,6,7,8]] Expected Result : ( list of strings ) ['Start - 3 , End - 4', 'Start - 7 , End - 8'] Note : First 2 values from each list should be ignored. Could anyone please guide me with best solution without loops ? output_list = [] t = ['Start','End'] a = [[1,2,3,4], [5,6,7,8]] output_list.append('%s - %s, %s - %s' % (t[0], a[0][2], t[1], a[0][3])) output_list.append('%s - %s, %s - %s' % (t[0], a[1][2], t[1], a[1][3])) print output_list -- John Gordon Imagine what it must be like for a real medical doctor to gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'. -- https://mail.python.org/mailman/listinfo/python-list
Re: Small script to check serial port sucking down system resources.
On 16/12/2013 14:31, sem...@gmail.com wrote: i am new to python and programming all together. i wrote a program to watch a serial port and look for a command. then send a tcp packet. all works great but it takes my processor load to about %25. not sure if there is a way to make this more efficient. import serial import socket HOST = '127.0.0.1'# The remote host PORT = 5250 # The same port as used by the server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) ## ser = serial.Serial( port='COM10',\ baudrate=9600,\ parity=serial.PARITY_NONE,\ stopbits=serial.STOPBITS_ONE,\ bytesize=serial.EIGHTBITS,\ timeout=0) print(connected to: + ser.portstr) #this will store the line line = [] c = 0 while True: for c in ser.readline(): line.append(c) if c == '1': s.send('CG 1-21 ADD 1 reserveisoff 1 \r\n') data = s.recv(1024) print 'Received', repr(data) print(one) line = [] break if c == '2': s.send('PLAY 1-1 AMB.mp4 \r\n') data = s.recv(1024) print 'Received', repr(data) s.send('LOADBG 1-1 EMPTY MIX 30 AUTO \r\n') data = s.recv(1024) print 'Received', repr(data) print(two) line = [] break s.close() ser.close() I think the problem might be that you've set the timeout to 0, so it doesn't block if there's no data available. -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
- Original Message - On Tue, Dec 17, 2013 at 5:26 AM, Jean Dubois jeandubois...@gmail.com wrote: Try something simple first: import telnetlib host = '10.128.59.63' port = 7000 t = Telnet(host, port) def flush() t.read_very_eager() def sendCmd(cmd) t.write('%s\n' % cmd) return flush() flush() print sendCmd('*IDN?') print sendCmd('*OPC?') Still no success: jean@mantec:~$ ./test.py File ./test.py, line 7 def flush() ^ SyntaxError: invalid syntax Tried it both with python2 and python3, same error... Folks, the OP isn't an expert. Please test your scripts before posting! I don't have everything I need to test this fully, but here's a variant of the above that's at least syntactically correct: from telnetlib import * host = '10.128.59.63' port = 7000 t = Telnet(host, port) def flush(): t.read_very_eager() def sendCmd(cmd): t.write('%s\n' % cmd) return flush() flush() print sendCmd('*IDN?') print sendCmd('*OPC?') It's written for Python 2, so use that interpreter. ChrisA It was done on purpose, for educational purpose... :) My bad, however I should point that learning the very basic of a language by implementing a low level equipment remote protocol is rather ambitious. By experience I know that you are annoyed by a crapload of nasty details without even caring about the python syntax, including: * LF/CR sequence * Inconsistent answer pattern, depending on the equipment vendor * broken netcode that can block the remote server * timeouts * poor equipment feedback I still wish Jean a great success :) JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Determining whether a glyph is available in Tkinter
On 12/16/2013 12:32 PM, wmcbr...@gmail.com wrote: I have a Tkinter app that can optionally label some buttons with certain Unicode glyphs that aren't always available (depending on the OS, etc.). It depends on the font in use. The best scenario would be to always use the same unicode font. Idle, built on tkinter, has a configuration dialog that gets a list of available fonts and sets the one the user selects. I use Lucida Sans Unicode. It is not very pretty, but it seems to cover much the BMP. AFAIK, it should be available on all Windows from XP on. I do not know what comes with *nix and mac, but from reading https://en.wikipedia.org/wiki/Unicode_font#List_of_Unicode_fonts there seem to be TrueType fonts that you could install with your software: FreeSerif (etc), GNU Unifont, (both GPL), BitstreamCyber (free for non-commercial use). The font table linked above is followed by table indicating something about coverage. Unifont is the champ. When they aren't available, Tkinter renders them as \u. What I'd like to do is check whether the glyphs are available, and fall back to my own alternate text for the button if not. Can I do this? Don't know. See the 'Utility software' section of the page above. I'd also like to do the same in pygtk. No idea. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
RE: Question RE urllib
Sorry to be a pain here, guys, as I'm also a newbie at this as well. Where, exactly in the script would I place the print str(e) ? Thanks Original message : I'm not really receiving an exception other than those three sites, out of the 30 or so I have listed, are the only sites which show is down at the end of that line specifying the site. Where # has been substituted for our domain name https://my..com/intranet.htmlhttps://my./#%23%23%23.com/intranet.html* is down* http://#.main..com/psso/pssignsso.asp?dbname=FSPRD90 * is down* http://sharepoint..com/regions/west/PHX_NSC/default.aspxhttp://sharepoint./#%23%23%23.com/regions/west/PHX_NSC/default.aspx * is down* So I'm using the following script to check our sites to make sure they are all up and some of them are reporting they are down when, in fact, they are actually up. These sites do not require a logon in order for the home page to come up. Could this be due to some port being blocked internally ? Only one of the sites reporting as down is https but all are internal sites. Is there some other component I should be including in the script ? There are about 30 or 40 sites that I have listed in all. I just use those in the following script as examples. Thanks import urllib sites = [http://www.amazon.com/;, https://internalsite.com/intranet.html;, etc.] for site in sites: try: urllib.urlopen(site) print site + except Exception, e: print site + is down In the handler print out the exception you are getting. If your exception handler is being called then you are indeed getting an exception. Add: print str(e) to the handler -- https://mail.python.org/mailman/listinfo/python-list
Re: Question RE urllib
On Mon, Dec 16, 2013 at 2:55 PM, Jeff James j...@jeffljames.com wrote: Sorry to be a pain here, guys, as I'm also a newbie at this as well. Where, exactly in the script would I place the print str(e) ? The line after the print site + is down line. Thanks Original message : I'm not really receiving an exception other than those three sites, out of the 30 or so I have listed, are the only sites which show is down at the end of that line specifying the site. Where # has been substituted for our domain name https://my..com/intranet.html is down http://#.main..com/psso/pssignsso.asp?dbname=FSPRD90 is down http://sharepoint..com/regions/west/PHX_NSC/default.aspx is down So I'm using the following script to check our sites to make sure they are all up and some of them are reporting they are down when, in fact, they are actually up. These sites do not require a logon in order for the home page to come up. Could this be due to some port being blocked internally ? Only one of the sites reporting as down is https but all are internal sites. Is there some other component I should be including in the script ? There are about 30 or 40 sites that I have listed in all. I just use those in the following script as examples. Thanks import urllib sites = [http://www.amazon.com/;, https://internalsite.com/intranet.html;, etc.] for site in sites: try: urllib.urlopen(site) print site + except Exception, e: print site + is down In the handler print out the exception you are getting. If your exception handler is being called then you are indeed getting an exception. Add: print str(e) to the handler -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Small script to check serial port sucking down system resources.
On 2013-12-16, MRAB pyt...@mrabarnett.plus.com wrote: On 16/12/2013 14:31, sem...@gmail.com wrote: i wrote a program to watch a serial port and look for a command. then send a tcp packet. all works great but it takes my processor load to about %25. not sure if there is a way to make this more efficient. import serial [...] ser = serial.Serial( port='COM10',\ baudrate=9600,\ parity=serial.PARITY_NONE,\ stopbits=serial.STOPBITS_ONE,\ bytesize=serial.EIGHTBITS,\ timeout=0) print(connected to: + ser.portstr) #this will store the line line = [] c = 0 The line above is useless -- it binds 'c' to the integer value 0, but then you rebind 'c' to something else without ever referencing that value. while True: for c in ser.readline(): line.append(c) if c == '1': s.send('CG 1-21 ADD 1 reserveisoff 1 \r\n') data = s.recv(1024) print 'Received', repr(data) print(one) line = [] break if c == '2': s.send('PLAY 1-1 AMB.mp4 \r\n') data = s.recv(1024) print 'Received', repr(data) s.send('LOADBG 1-1 EMPTY MIX 30 AUTO \r\n') data = s.recv(1024) print 'Received', repr(data) print(two) line = [] break s.close() ser.close() I think the problem might be that you've set the timeout to 0, so it doesn't block if there's no data available. That is indeed the problem. When there's no serial data you're spinning around in that loop as fast as your CPU can go. Try setting timeout = None when you set up the serial port. That way the call to ser.readline() will block (IOW won't return) until there's actually data to be processed. While blocked waiting for serial data, your program won't be using up any CPU time. Your for loop with breaks looks odd2. Can you explain what it's suposed to be doing? You seem to be using the for loop to iterate through the characters in each input line, but then breaking out of the loop the first time you see either a '1' or '2' in each line. Is that what you intended? -- Grant Edwards grant.b.edwardsYow! Quick, sing me the at BUDAPEST NATIONAL ANTHEM!! gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Concatenate string list to number list to form title - Logic needed.
On 12/16/2013 12:43 PM, Mark Lawrence wrote: On 16/12/2013 17:16, Ravi Prabakaran wrote: Hi, I'm completely new to python. I just need simple logic to get output without any loops. I have list of string The remainder of your description and example imply that this must be a sequence of exactly two strings. In other words, 'list' is both too specific as to class and not specific enough as to length. and list of list of numbers. While this must be an iterable of sequences of exactly 4 numbers. Each string should be concatenated with every third and fourth values to generate proper titles in list of strings. t = ['Start','End'] a = [[1,2,3,4], [5,6,7,8]] Expected Result : ( list of strings ) ['Start - 3 , End - 4', 'Start - 7 , End - 8'] Note : First 2 values from each list should be ignored. Could anyone please guide me with best solution without loops ? If the length of the iterable of sequences is not fixed, a loop of some sort is needed. I've no idea what your definition of best is but this works. strings = ['{} - {} , {} - {}'.format(t[0], b[-2], t[1], b[-1]) for b in a] Very nice. The following use the format mini language to do the indexing, avoiding passing the args twice each. strings = ['{0[0]} - {1[2]} , {0[1]} - {1[3]}'.format(t, b) for b in a] form = '{src[0]} - {val[2]} , {src[1]} - {val[3]}' strings = [form.format(src=t, val=b) for b in a] The first should be faster, but may be less readable. Note that '-2' and '-1' do not work as int indexes in the field names because they would be interpreted as string keys rather than integers. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Question Re urllib (Resolved)
This worked perfectly. Thank You Where, exactly in the script would I place the print str(e) ? The line after the print site + is down line. Original Post : I'm not really receiving an exception other than those three sites, out of the 30 or so I have listed, are the only sites which show is down at the end of that line specifying the site. Where # has been substituted for our domain name https://my..com/intranet.html https://my./#%23%23%23.com/intranet.html* is down* http://#.main..com/psso/pssignsso.asp?dbname=FSPRD90 * is down* http://sharepoint..com/regions/west/PHX_NSC/default.aspxhttp://sharepoint./#%23%23%23.com/regions/west/PHX_NSC/default.aspx * is down* So I'm using the following script to check our sites to make sure they are all up and some of them are reporting they are down when, in fact, they are actually up. These sites do not require a logon in order for the home page to come up. Could this be due to some port being blocked internally ? Only one of the sites reporting as down is https but all are internal sites. Is there some other component I should be including in the script ? There are about 30 or 40 sites that I have listed in all. I just use those in the following script as examples. Thanks import urllib sites = [http://www.amazon.com/;, https://internalsite.com/intranet.html , etc.] for site in sites: try: urllib.urlopen(site) print site + except Exception, e: print site + is down In the handler print out the exception you are getting. -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
I am sorry if the way I posted messages was incorrect. Like I said, I am new to google groups and python quite a bit but i am trying to do things correctly by you guys. The errors that I am getting were not necessarily posting traceback messages. In those messages I posted my last bit of confusion, how to properly run the program while meeting the arguments. Thanks Frank for giving me a little hint at that. Now in that directory in cmd, i type in python twitch.py 10 10. When i do this I get thread error posting infinitely down my stream. So it looks like the program is actually running now, just some im possibly missing? Once again I do have pip and livestreamer installed and the exact py file i have is located here: http://www.mediafire.com/view/3m10s9rwvatxd96/twitch.py Once again thanks for help, Mark -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
And ever after that experience, I avoided all languages that were even remotely similar to C, such as C++, Java, C#, Javascript, PHP etc. I think that's disappointing, for two reasons. Firstly, C syntax isn't that terrible. It's not just the abysmally appalling, hideously horrifying syntax. At about everything about C is just *not* made for human beings imho. It's just an un-language that gets at about everything wrong. Sort of like Microsoft's products. Sincerely, Wolfgang -- https://mail.python.org/mailman/listinfo/python-list
Re: Question RE urllib
In mailman.4234.1387223734.18130.python-l...@python.org Jeff James j...@jeffljames.com writes: --f46d04479f936227ee04edac31bd Content-Type: text/plain; charset=ISO-8859-1 Sorry to be a pain here, guys, as I'm also a newbie at this as well. Where, exactly in the script would I place the print str(e) ? except Exception, e: print site + is down print str(e) -- John Gordon Imagine what it must be like for a real medical doctor to gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'. -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
Op maandag 16 december 2013 20:21:15 UTC+1 schreef Jean-Michel Pichavant: - Original Message - On Tue, Dec 17, 2013 at 5:26 AM, Jean Dubois jeandubois...@gmail.com wrote: Try something simple first: import telnetlib host = '10.128.59.63' port = 7000 t = Telnet(host, port) def flush() t.read_very_eager() def sendCmd(cmd) t.write('%s\n' % cmd) return flush() flush() print sendCmd('*IDN?') print sendCmd('*OPC?') Still no success: jean@mantec:~$ ./test.py File ./test.py, line 7 def flush() ^ SyntaxError: invalid syntax Tried it both with python2 and python3, same error... Folks, the OP isn't an expert. Please test your scripts before posting! I don't have everything I need to test this fully, but here's a variant of the above that's at least syntactically correct: from telnetlib import * host = '10.128.59.63' port = 7000 t = Telnet(host, port) def flush(): t.read_very_eager() def sendCmd(cmd): t.write('%s\n' % cmd) return flush() flush() print sendCmd('*IDN?') print sendCmd('*OPC?') It's written for Python 2, so use that interpreter. ChrisA It was done on purpose, for educational purpose... :) My bad, however I should point that learning the very basic of a language by implementing a low level equipment remote protocol is rather ambitious. By experience I know that you are annoyed by a crapload of nasty details without even caring about the python syntax, including: * LF/CR sequence * Inconsistent answer pattern, depending on the equipment vendor * broken netcode that can block the remote server * timeouts * poor equipment feedback I still wish Jean a great success :) I'm a newbie in Python programming that is very much true, and contrary to what you seem to suggest I did my homework: I succeeded already in writing a Python-script which communicates directly over rs232 with the same device which I now am trying to connect to via a rs232-ethernet adapter. So I thought it would be simply a matter of communicating the same commands as I did before. Here are some parts of my code: serkeith = serial.Serial('/dev/ttyUSB0', 9600, 8, timeout=5, xonxoff=1) serkeith.write(*RST + \n) #turn off concurrent functions serkeith.write(:SENS:FUNC:CONC OFF + \n) #current source function serkeith.write(:SOUR:FUNC CURR + \n) #volt sense function serkeith.write(:SENS:FUNC 'VOLT:DC' + \n) #105V compliance #serkeith.write(:SENS:VOLT:PROT 105 + \n) compliancestring=':SENS:VOLT:PROT '+str(compliancevalue) + '\n' serkeith.write(compliancestring) . . keithleymeasurement=serkeith.readline().split(',') Also I got it working with nc and telnet, I just don't know how to accomplish this using python. Tomorrow I'll look further at some a the more recent suggestions kind regards, jean -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
Let the flame war begin! Am 16.12.13 17:10, schrieb Chris Angelico: Here's the Tcl procedure that I tweaked. This is from gitk; I find the word diff not all that useful, but a character diff at times is very useful. I haven't found a way to configure the word diff regex through gitk's options, so I tweaked it in the source code. proc getblobdiffs {ids} { global blobdifffd diffids env global diffinhdr treediffs global diffcontext global ignorespace global worddiff global limitdiffs vfilelimit curview global diffencoding targetline diffnparents global git_version currdiffsubmod . } I'm a long time Tcl developer who has just picked up Python recently; so my view is tinted from the other side. First off, gitk is a huge unstructured mess. You are not obliged to write programs like this in Tcl, at least not today. All these global statements give already a hint, that this is a procedural thing. Think of Python, where classes are stripped. Tcl has object oriented frameworks for years. If you use Snit, e.g., all those globals are not needed because they are really instance variables. First off, everything's done with commands, rather than assignment (set diffinhdr 0), which is very shell-style and not very programming-style. This is just syntax and purely a matter of taste. Can live with that, though even shells can use equals signs for simplicity. Similarly, the shell style of adorning variable usage feels messy. There are string literals, some of which contain interpolated variables; there are dollar-sign adorned variables; and then there are other words. What are the other words? Are they implicit strings (as they would be in, say, bash)? Yes, they are, and it doesn't feel strange if you are used to it. Tcl's syntax rules are very compact. Tclers see this as an advantage. Secondly, what does this do? if {$worddiff ne [mc Line diff]} I *think* it means 'if $worddiff is not equal to Line diff (this code is executed for the options Markup words and Color words, but what's the mc do? It does command substitution (indeed the brackets [] do) and is one of the key concepts of Tcl. mc is probably the command from msgcat which translates i18n strings. Complaining about these basic things is like complaining about indentation in Python. This is where, IMO, Python tends to be a lot clearer. It's easy to see what's an object and what's a method on it, and every bare word is either a local name or a standard built-in name. I'm sure Tcl's a great language, but I'd rather not have to drop out of Python into it if I can help it. :) Python has some advantages over Tcl. To name a few, references, list comprehensions, real classes, clean module support, extensive extensions such as matplotlib/scipy. But Tcl also has some strengths. First off, the syntax is quite flexible, and so things like list comprehensions[1] or classes[2] can be implemented in Tcl itself. Second, it's great at interactive use because at a command prompt, you don't want to type all those () call operators, quotes and obey indentation just to get a simple loop running. Third, its implementation features a few unique things: * Stubs. Compile a C extension against 8.1 and load it into 8.6. This actually works. 8.1 was nearly 15 years ago! * Safe interpreters. Sometimes requested here for Python, you can create a slave interpreter in Tcl that is restricted and cannot do disk I/O, has limited execution time etc. You can precisely control which commands are passed on to the slave. * Interpreters in threads. There is no GIL, Tcl interpreters are thread safe and more than one can coexist in a process and run concurrently. This is accessible from script level through the Threads package. * Very easy deployment: Starkits/Tclkits bundle an interpreter within a single executable. Similar to what pyinstaller does. But in my experience, it's much easier to pack all dependencies into a starkit than it is with pyinstaller. You can get a rather full-fledged interpreter with GUI support into a few megabytes, and I've never seen it fail. Happy flaming, Christian [1] http://wiki.tcl.tk/12574 [2] http://wiki.tcl.tk/3963 -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
Am 16.12.13 18:04, schrieb Grant Edwards: On 2013-12-16, Chris Angelico ros...@gmail.com wrote: On Tue, Dec 17, 2013 at 3:46 AM, Grant Edwards invalid@invalid.invalid wrote: * The everything is a string view of the world is severly limiting if you're not just processing strings. I wasn't sure if that was the case, from what I was seeing. Are there any aggregate types at all? There are arrays with string keys (similar to Python dictionaries). Aggregate types are indeed a weak point, but still there are lists (since ever) and dicts (since 8.5, ~6 years) with value semantics. Arrays are distinct from dicts and provide no value semantics, i.e. you cannot pass them around. Today these issues are overcome by using dicts or some OO framework. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Type of an object: ‘obj.__class__’ versus ‘type(obj)’
On Mon, 16 Dec 2013 12:51:21 +1100, Ben Finney wrote: Howdy all, What is the Pythonic way to determine the type of an object? Are there multiple valid ways, and when should each be used? That is an excellent question, I only wish I had an excellent answer to give you. Obviously great minds think alike because I was going to ask the same question, prompted by this comment from Nick Coghlan on the python-dev list: ...type(obj).__name__ (working with the concrete type, ignoring any proxying) or obj.__class__.__name__ (which takes proxying into account)... So there is a difference between them, but I'm not entirely sure what it is. We have ‘obj.__class__’, an attribute bound to the object's class. Or is it? When is that true, and when should we not rely on it? I think you can rely on it. I don't believe you can delete the __class__ attribute from an instance: py class X(object): ... pass ... py x = X() py x.__class__ class '__main__.X' py del x.__class__ Traceback (most recent call last): File stdin, line 1, in module TypeError: can't delete __class__ attribute I think it is fair to consider __class__ to be part of the object API shared by all objects. I suppose it's possible to create a metaclass which does not expose a __class__ attribute, but I would consider that broken by design. Furthermore, you can dynamically set the __class__ of an instance in order to dynamically change its type and therefore behaviour (although there are restrictions on what you can change it to, and from). Using the same x instance as above: py class Y(object): ... pass ... py x.__class__ = Y py type(x) class '__main__.Y' This is by design, and it allows a very useful form of dynamic behaviour: http://code.activestate.com/recipes/68429-ring-buffer/ We have ‘type(obj)’, calling the constructor for the ‘type’ type in order to get a reference to the type of ‘obj’. Or is it? When is that true, and when should we not rely on it? Are there circumstances where type(obj) and obj.__class__ return something different? Based on Nick's comment above, I would have to guess the answer must be yes, but I don't know what those circumstances are. Aside: I'm not sure that it is useful to think of type as the constructor in the one-argument form. If you recall, prior to Python 2.2 `type` was a regular function which took one argument and returned the argument's type: [steve@ando ~]$ python1.5 Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam type built-in function type The types returned were very different from the types we know and love since the class/type unification of version 2.2: type(42) type 'int' int built-in function int type(42)('2') Traceback (innermost last): File stdin, line 1, in ? TypeError: call of non-function (type type) So while it is *technically* correct that type(...) calls the type constructor, the one-argument form type(obj) is intended to behave as a function, while the three-argument form type(name, bases, namespace) is intended to behave as a constructor of types. But I digress. Are there other ways to get at the type of a Python object? What reasons are there to choose or avoid them? I am not aware of any other ways. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
[newbie] Saving binaries in a specific way
Hi all, I am new to this forum and also to Python, but I'm trying hard to understand it better. I need to create a binary file, but the first 4 lines must be in signed-Integer16 and all the others in signed-Integer32. I have a program that does that with Matlab and other with Mathematica, but I'm converting all for Python. I tried first to convert the number to binary using 'bin(number'), than I removed the '0b' and converted to 'Int16' or 'Int32', but with this approach I can't save a binary file using 'bytearray('). How can I do that? Thanks in advance. -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] Saving binaries in a specific way
On Mon, Dec 16, 2013 at 2:19 PM, Djoser pedrovg...@gmail.com wrote: Hi all, I am new to this forum and also to Python, but I'm trying hard to understand it better. I need to create a binary file, but the first 4 lines must be in signed-Integer16 and all the others in signed-Integer32. I have a program that does that with Matlab and other with Mathematica, but I'm converting all for Python. I tried first to convert the number to binary using 'bin(number'), than I removed the '0b' and converted to 'Int16' or 'Int32', but with this approach I can't save a binary file using 'bytearray(') How can I do that? What you probably want is to use the struct module: http://docs.python.org/3/library/struct.html You probably also want the open method and file objects: http://docs.python.org/3/library/functions.html#open It would help if you provided information about which Python version you are using, and exactly what you mean by I can't save a binary file using 'bytearray('). Do you get a traceback, if so, copy it in your message, along with actual code that produces your problem (preferably simplified, but not too far). -- https://mail.python.org/mailman/listinfo/python-list
Re: Packaging a private project
On Dec 16, 2013 11:20 AM, Nicholas Cole nicholas.c...@gmail.com wrote: Dear List, What is the best way to distribute a private, pure python, Python 3 project that needs several modules (some available on pypi but some private and used by several separate projects) in order to run? I'd like to include everything that my project needs to run in a single package. The best way to do this seems to be to be to create symlinks to the source code of the 3rd party modules I need and create a setup.py file that includes them in its packages list. Is this what other people do? But even more ideally, I'd like to package my script and its dependencies in a single zip file that can be executed by python directly. I see several declarations that this is possible online, but I can't find a simple recipe for converting a script and its dependencies into this kind of distribution. Could someone give me a pointer to a description of the right way to do it. For pure python code it's as simple as putting the code in a zip file with a script called __main__.py. Then you can run the zip file with python as if it was a python script. Oscar -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] Saving binaries in a specific way
I'm using python 2.7. If I understood correctly, using bytearray I will lost the information about the signed 16, 32, since it makes automatically the conversion. Do you think that I can make the conversion as I proposed before or using struct and save with open()? -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On Tue, Dec 17, 2013 at 9:06 AM, Christian Gollwitzer aurio...@gmx.de wrote: Let the flame war begin! I'll try to avoid flamage :) First off, gitk is a huge unstructured mess. You are not obliged to write programs like this in Tcl, at least not today. All these global statements give already a hint, that this is a procedural thing. Think of Python, where classes are stripped. Tcl has object oriented frameworks for years. If you use Snit, e.g., all those globals are not needed because they are really instance variables. Ah, okay. Don't take gitk as representative. Got it. Unfortunately there are quite a few languages that I've experienced from, really, only one program that I've tried to modify (Scheme almost falls in that category too - all I've ever used it for is LilyPond scripting, and not much of that), and I'm aware that's not really a fair look at the language. First off, everything's done with commands, rather than assignment (set diffinhdr 0), which is very shell-style and not very programming-style. This is just syntax and purely a matter of taste. Yeah. Like I said, Can live with that . But my rule of thumb with bash scripts is: If it exceeds a page or two in length, it's probably time it got rewritten in an application language. When a program is the size of gitk (10KLOC), the benefits relating to interactive use (as you mention below) become less significant, and benefits relating to discoverability of the more obscure features become more significant. It does command substitution (indeed the brackets [] do) and is one of the key concepts of Tcl. mc is probably the command from msgcat which translates i18n strings. Complaining about these basic things is like complaining about indentation in Python. Okay. Now, how am I to figure out where this command comes from? It's not a host command (typing mc at the bash prompt comes up failure), and it's not defined in the script itself (at least, I can't find proc mc anywhere); is it a Tcl built-in? Where do I start looking? (Yes, I'm aware this is a problem in any language. I'm not now raising a point in the Python vs Tcl debate, I'm just asking out of curiosity.) Tcl also has some strengths. First off, the syntax is quite flexible, and so things like list comprehensions[1] or classes[2] can be implemented in Tcl itself. Second, it's great at interactive use because at a command prompt, you don't want to type all those () call operators, quotes and obey indentation just to get a simple loop running. Third, its implementation features a few unique things: Yeah, that's nice for the interactive interpreter... but I already have bash for that, and Python's not far off. I've used interactive Pike and REXX interpreters, which are both more demanding than Python (in terms of syntax requirements and such), so I'm perfectly happy with Python; but if you're used to something even lighter, then sure, use something that lets you type almost nothing. No problem. I just think that - as mentioned above - a ten thousand line program should be aiming more at maintainability than ease of manual typing. * Safe interpreters. Sometimes requested here for Python, you can create a slave interpreter in Tcl that is restricted and cannot do disk I/O, has limited execution time etc. You can precisely control which commands are passed on to the slave. Cool. Not enough for me to choose the language unless I really REALLY needed that feature, but there was one time in my programming career when that was true, so we'll count that a win. * Interpreters in threads. There is no GIL, Tcl interpreters are thread safe and more than one can coexist in a process and run concurrently. This is accessible from script level through the Threads package. Nice, though Python's threading and/or multiprocessing can do 90% of what people want. Side point: What about Tk? Can you (a) run separate GUI threads for separate windows? (b) manipulate widgets created by another thread? * Very easy deployment: Starkits/Tclkits bundle an interpreter within a single executable. Similar to what pyinstaller does. But in my experience, it's much easier to pack all dependencies into a starkit than it is with pyinstaller. You can get a rather full-fledged interpreter with GUI support into a few megabytes, and I've never seen it fail. Never really needed this, but for the people who do, I'm sure that's a fairly big deal. So there definitely are some advantages that Tcl has over Python. Put against them is a superior object model, a large corpus of first-class object types (dict, set, list, etc[1]), and a syntax that more clearly differentiates names and strings without making variable references look like a lot more than they are. Huge room in the world for both languages to exist and thrive. ChrisA [1] What is an etc() in Python? -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
Grant Edwards wrote: On 2013-12-16, Chris Angelico ros...@gmail.com wrote: Are there any aggregate types at all? There are arrays with string keys (similar to Python dictionaries). Well... sort of. They can only hold strings, not other arrays. They're not first-class entities: you can't pass them around or keep them in local variables; they're always global. (And there are no modules, so global is *truly* global.) In short, they're a very poor substitute for having real data structures. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] Saving binaries in a specific way
On 2013-12-16 14:19, Djoser wrote: I am new to this forum and also to Python, but I'm trying hard to understand it better. Welcome aboard! I need to create a binary file, but the first 4 lines must be in signed-Integer16 and all the others in signed-Integer32. I have a program that does that with Matlab and other with Mathematica, but I'm converting all for Python. You seem to be conflating ideas here: a binary file doesn't really have lines. Do you mean first 4 bytes? If so, then a signed-Integer16 really only occupies 2 bytes, so you'd have to pad it somehow. That said, I suspect that the struct module will get you what you want: from struct import pack header16bit = 31415 data = list(range(10)) with open('output.bin', 'wb') as f: f.write(pack('h', header16bit)) for signed_32bit_number in data: f.write(pack('i', signed_32bit_number)) f.write(other_stuff) You might need to specify the byte-ordering, which you can do by prefixing the h or i with , or = s documented at [1] -tkc [1] http://www.python.org/doc//current/library/struct.html . -- https://mail.python.org/mailman/listinfo/python-list
Re: min max from tuples in list
Ned Batchelder wrote: On 12/16/13 10:49 AM, rusi wrote: And things that have consistency are of course... consistant (not consistent) In English, it's spelled consistent: http://en.wiktionary.org/wiki/consistant So to be consistent we should spell it performent? :-) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Mon, 16 Dec 2013 20:32:25 -, Wolfgang Keller felip...@gmx.net wrote: And ever after that experience, I avoided all languages that were even remotely similar to C, such as C++, Java, C#, Javascript, PHP etc. I think that's disappointing, for two reasons. Firstly, C syntax isn't that terrible. It's not just the abysmally appalling, hideously horrifying syntax. At about everything about C is just *not* made for human beings imho. It's an excellent macro assembler, so of course it's not made for human beings. Unfortunately the software development took one look at it and exclaimed, It's a hammer, all our problems must be nails! And the rest is C++. -- Rhodri James *-* Wildebeest Herder to the Masses -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] Saving binaries in a specific way
Basically I have a .dat file, so I get some numbers and make a different conversion. I'll try this struct script. I'm not used to it, but it seems to do what I want. -- https://mail.python.org/mailman/listinfo/python-list
Re: Determining whether a glyph is available in Tkinter
I'm not going to control the font. This is for a program that's distributed to the general public, for use on a wide variety of systems. But what I do in the current version is to use the ASCII label strings by default, and have a command-line option to select the graphical (non-ASCII Unicode) labels. What I want is to make the graphical labels the default, and have the program detect, at runtime, whether any of the glyphs used in the fancy labels would render as \u in whatever the default font for the buttons is, and automatically revert to the ASCII labels in that case. I'm assuming this is possible, because Tkinter itself seems to know which glyphs are unavailable, or they'd probably be showing up as those boxed number characters or question marks instead of \u. -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On 12/16/2013 5:40 PM, Chris Angelico wrote: Nice, though Python's threading and/or multiprocessing can do 90% of what people want. Side point: What about Tk? Can you (a) run separate GUI threads for separate windows? (b) manipulate widgets created by another thread? When running tk via tkinter, limiting tkinter/tk calls to the main thread is the safest thing to do. I do not know whether the problems people have had doing otherwise are due to Python or inherent in tk itself. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list