[Tutor] Connecting with running module and capturing the data
Hi All, I am a beginner in python and have just started using it a couple weeks ago. I am using python 3.4.3 on windows 7 machine together with IDLE 3.4.3 for compiling a code. The following steps are: I have a program, called PyAquire, such as: import PyAquireUi import sys from PySide import QtGui import PyAquireMain def main(): master = PyAquireMain.PyAquireMain() app = QtGui.QApplication(sys.argv) ex = PyAquireUi.PyAquireMainWindow(master) sys.exit(app.exec_()) if __name__ == '__main__': main() which opens a new window, where by clicking RUN/STOP button, program acquires data. The data is running in the window. Program runs in the background, acquiring data all the time and my task is to write a code, where I will be able a) to connect with this program without interrupting the process b) capture the current available data c) and save data to excel file. The code I have written is: import PyAquireMain def main(): obj = PyAquireMain.PyAquireMain()# Create instance obj obj.saveSweepData()# call the method from PyAquireMain to save the file if __name__ == '__main__': main() saveSweepData function from PyAquireMain is: def saveSweepData(self): fileSuffix = QtCore.QDateTime.currentDateTime().toString('-MM-dd_hh.mm.ss') fileType = '.csv' # was .txt if self.ch1.yData is not None: saveFileName = 'data' + fileSuffix + fileType with open(os.path.join(self.settings.saveDir,saveFileName),'wb') as f: #f.writelines(header) np.savetxt(f,self.ch1.yData,fmt='%d',delimiter='\n') Therefore the question is how can I access the PyAquireMain, capture data and save file simultaneously when other program is running in the background. Thanks, Patrycja ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Design question: Web-based vs. desktop-based vs. desktop-based with data backed up to web server with a tablet thrown in for all cases?
On 20/07/15 04:59, boB Stepp wrote: implementing features of kivy on this list? I imagine that they would ...But I'm sure there is a kivy list somewhere I guess I will answer this question myself: I have just been skimming through the kivy docs tonight and they look to be quite good. Also, I found their Google group and it looks to be quite active. So unless I have a GUI question that seems to fit better here, I will direct my kivy inquiries to their Google group. right answer ;-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Socket Module
On 20/07/15 00:55, Nym City via Tutor wrote: Thank you for your response. I gave it another try: As suggested, first I ran the concept just in the terminal, and it worked fine: names =['173.252.120.6', '98.139.183.24'] import socket for name in names: socket.gethostbyaddr(name) print(name) output: ('edge-star-shv-12-frc3.facebook.com', [], ['173.252.120.6']) ('ir2.fp.vip.bf1.yahoo.com', [], ['98.139.183.24']) Remember that the >>> prompt evaluates your results and automatically prints them for you. Thus >>> 5 + 3 8 But if you put code in a script and execute it the interpreter does NOT print out arbitrary expressions so a file add.py containing just 5 + 3 will not output anything, you need the print function: print(5+3) to see the result. So in the interpreter your gethostbyaddr() function is evaluated AND printed. But in a script it will only be evaluated... import csv import socket domains = [] with open('top500ips.csv', 'r') as f: for line in f: line = line.strip() domains.append(line) You are importing csv but not using it to read your file. But I'll ignore that for now! (in fact it looks like the csv file really only contains the IP addresses, one per line so csv is probably redundant here.) Also you could do all of the above in a single line with: domains = [line.strip() for line in open('top500ips.csv')] But none of that matters for your specific issue... for name in domains: socket.gethostbyaddr(name) print(name) Notice here that you run the gethostbyaddr() function but do nothing with the result. You don't store it and you don't print it. Instead you print the initial name that you passed in, which does not change. You need to create a variable to store the host result and then print that host. And since you want to store a set of hosts you probably want to append the results to a list of some kind (or a dictionary based on your names?) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Connecting with running module and capturing the data
On 20/07/15 08:26, Patrycja Niewosz wrote: I am a beginner in python and have just started using it a couple weeks ago. I am using python 3.4.3 on windows 7 machine together with IDLE 3.4.3 for compiling a code. The following steps are: I have a program, called PyAquire, such as: Can you tell us where you got it? I did a search and the only one I could find was called pyacquire (with a c) and seems to be an astronomy tool that is allegedly hosted on google code but the site has no code! And no wiki entries or issues or logged changes - in short its dead! Is this the same package or something else? (Or did you write it yourself?) The reason I did the search is that this list is for questions about the Python language and its standard library so normally I'd suggest you ask on the pyaquire list or forum. But since I can't find one that's not much help! The only other place you might get help is the main Python mailing list. import PyAquireUi import sys from PySide import QtGui For PySide questions you can try any of several Qt mailing lists/fora import PyAquireMain def main(): master = PyAquireMain.PyAquireMain() app = QtGui.QApplication(sys.argv) ex = PyAquireUi.PyAquireMainWindow(master) sys.exit(app.exec_()) if __name__ == '__main__': main() which opens a new window, where by clicking RUN/STOP button, > program acquires data. The data is running in the window. Program runs in the background, acquiring data all the time That last line is probably not true, but without knowing more about the module I can't be sure. However I strongly suspect that it is probably running within an event loop which gives your code the opportunity to register an event whereby you can intercept the results. But without any sign of code or documentation we can't really help. a) to connect with this program without interrupting the process > b) capture the current available data See comment above but we need to see the API. c) and save data to excel file. There are a couple of modules for saving to Excel native format, but I'd suggest you use a csv file instead since that is compatible with most spreadsheets etc - not everyone uses Excel and you might have to share the results someday! The csv module will do that for you. The code I have written is: import PyAquireMain def main(): obj = PyAquireMain.PyAquireMain()# Create instance obj obj.saveSweepData()# call the method from PyAquireMain to save the file Its not clear how this relates to the other program above? Do you run the previous code in one interpreter and this code in another? That's almost certainly the wrong way to go about things. saveSweepData function from PyAquireMain is: def saveSweepData(self): fileSuffix = QtCore.QDateTime.currentDateTime().toString('-MM-dd_hh.mm.ss') fileType = '.csv' # was .txt if self.ch1.yData is not None: saveFileName = 'data' + fileSuffix + fileType with open(os.path.join(self.settings.saveDir,saveFileName),'wb') as f: #f.writelines(header) np.savetxt(f,self.ch1.yData,fmt='%d',delimiter='\n') This doesn't help us very much except that the reference to np suggests this might be part of numpy so the numpy or scipy fora might be able to help. Therefore the question is how can I access the PyAquireMain, capture data and save file simultaneously when other program is running in the background. It all depends on how pyaquire does its job. One possibility might be to use the new asyncio module in Python 3.4 but until we know more about this module we can't be sure. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Identifying V3 examples
I’m having problems identifying sites that feature V3 code. My learning is being hampered by having to worry about conversion for the vast majority of the examples I encounter. Any suggestions on how to deal with this? Jon Paris jon.f.pa...@gmail.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Identifying V3 examples
On 20/07/15 15:53, Jon Paris wrote: I’m having problems identifying sites that feature V3 code. The simplest clues are print foo -> v2 print(foo) -> v3 import Tkinter -> v2 import tkinter -> v3 However, mostly it doesn't make much difference. Are there particular sites or code issues you are having problems with? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Identifying V3 examples
On Mon, Jul 20, 2015 at 10:53:32AM -0400, Jon Paris wrote: > I’m having problems identifying sites that feature V3 code. My > learning is being hampered by having to worry about conversion for the > vast majority of the examples I encounter. > > Any suggestions on how to deal with this? This can be an issue for beginners, so I'm sure you are not alone. But remember, Python 2 and Python 3 share about 98% of the language, the differences are quite small. The most general way to deal with this, in my opinion, is to have both Python 2 and Python 3 installed, and try the example in both and see which one it works in. The most obvious hint that you're using Python 3 is the use of print() with round brackets (parentheses), that is, print as a function: print x # Works in v2, syntax error in v3 print(x) # Likely to be v3 The second most obvious hint is the use of Unicode ("funny non-ASCII characters") as ordinary strings, without the u prefix: s = u"ßŮƕΩжḜ※€ℕ∞⌘⑃☃だ" # Probably v2 s = "ßŮƕΩжḜ※€ℕ∞⌘⑃☃だ" # Probably v3 I say "probably" because, starting with version 3.3, Python 3 also supports the u"..." format, to make it easier to port code from v2 to v3. There are a few other changes, like the use of x.next() changing to next(x), some changes in behaviour, some libraries were renamed for consistency with the rest of the standard library, some functions were moved around, etc. If you google for "Python 2 3 changes", you will find plenty of places talking about this: https://duckduckgo.com/html/?q=python+2+3+changes https://startpage.com/do/search?q=python+2+3+changes If in doubt, feel free to ask here! -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] tkinter window not showing max, min and close buttons
I am working my way through Alan Gauld's tutorial and have just started the section on GUI. The windows that are created look odd with no title bar or maximise, minimise or close window button. system Python 2.7 (32 bit) Ubuntu Linux (unity) How might I get things to look like in the tutorial? Thank you Chris Roy-Smith ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor