Re: [Tutor] How to get MAC address using Python at windows 7
On 07/09/12 01:37, Steven D'Aprano wrote: On 06/09/12 23:44, bob gailer wrote: On 8/18/2012 10:12 AM, šãñ wrote: I need to find some way how i can get mac address of windows 7 Ethernet adapters have MAC addresses. Your computer will have one or more Ethernet adapter. Just to be pedantic, your computer will have ZERO or more Ethernet adapters. Although if you are receiving email and getting on the Internet on your computer, it must have at least one. Unless you are using dial-up... :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] urllib2.urlopen(....., timeout=)
2.7.3 According to the docs, urlopen has a timeout capability. But it says that the timeout = '' I've tried integers as the timeout value, I've tried floatsit doesn't complain about my values, but neither does it timeout. Can anyone point me to the solution to getting the urlopen to timeout if the target system isn't responding for some reason? What kind of objects is it expecting? Ray ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib2.urlopen(....., timeout=)
On 09/07/2012 11:16 AM, Ray Jones wrote: > 2.7.3 > According to the docs, urlopen has a timeout capability. But it says > that the timeout = '' > > I've tried integers as the timeout value, I've tried floatsit > doesn't complain about my values, but neither does it timeout. Can > anyone point me to the solution to getting the urlopen to timeout if the > target system isn't responding for some reason? What kind of objects is > it expecting? > I'm curious why the docstring says... timeout = but have no clues for you. See http://docs.python.org/library/urllib2.html which says: The optional /timeout/ parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used). This actually only works for HTTP, HTTPS and FTP connections. So I'd figure it wants an int, or maybe a float, as you've tried. is it possible that you're opening something which is neither HTTP, HTTPS nor FTP? What parameters exactly are you passing to urlopen ? I hope somebody can help more. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib2.urlopen(....., timeout=)
On 08/09/12 01:16, Ray Jones wrote: 2.7.3 According to the docs, urlopen has a timeout capability. But it says that the timeout = '' Which docs are those? According to these docs: http://docs.python.org/library/urllib2.html "The optional timeout parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used). This actually only works for HTTP, HTTPS and FTP connections." I've tried integers as the timeout value, I've tried floatsit doesn't complain about my values, but neither does it timeout. Can you give an actual working example of what you have tried, what you expect to happen, and what actually happens? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib2.urlopen(....., timeout=)
On 09/07/2012 08:33 AM, Steven D'Aprano wrote: > On 08/09/12 01:16, Ray Jones wrote: >> 2.7.3 >> According to the docs, urlopen has a timeout capability. But it says >> that the timeout = '' > > Which docs are those? According to these docs: > > http://docs.python.org/library/urllib2.html > > "The optional timeout parameter specifies a timeout in seconds for > blocking operations like the connection attempt (if not specified, > the global default timeout setting will be used). This actually > only works for HTTP, HTTPS and FTP connections." > I was looking at the doc strings(?) in iPython's help system. > Can you give an actual working example of what you have tried, what > you expect to happen, and what actually happens? > See my response to Dave Angel, and thanks for the reply. Ray ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib2.urlopen(....., timeout=)
On 09/07/2012 08:32 AM, Dave Angel wrote: > On 09/07/2012 11:16 AM, Ray Jones wrote: >> 2.7.3 >> According to the docs, urlopen has a timeout capability. But it says >> that the timeout = '' >> >> I've tried integers as the timeout value, I've tried floatsit >> doesn't complain about my values, but neither does it timeout. Can >> anyone point me to the solution to getting the urlopen to timeout if the >> target system isn't responding for some reason? What kind of objects is >> it expecting? >> > I'm curious why the docstring says... timeout = > but have no clues for you. > > See http://docs.python.org/library/urllib2.html > > which says: > > The optional /timeout/ parameter specifies a timeout in seconds for > blocking operations like the connection attempt (if not specified, the > global default timeout setting will be used). This actually only works > for HTTP, HTTPS and FTP connections. > > So I'd figure it wants an int, or maybe a float, as you've tried. is it > possible that you're opening something which is neither HTTP, HTTPS nor > FTP? What parameters exactly are you passing to urlopen ? My urlopen string is the following: urllib2.urlopen('http://%s:%s' % (ip, port), 'timeout = 2') Aha! See my problem? I just noticed it. I've been treating the 'timeout' portion as though I'm passing it as a command line parameter or something. I removed the quotes and all is swell! Y'all are awesome. Even when you don't have enough information to know the solution you help me! :) Ray ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib2.urlopen(....., timeout=)
On Fri, Sep 7, 2012 at 11:32 AM, Dave Angel wrote: > > I'm curious why the docstring says... timeout = > but have no clues for you. socket._GLOBAL_DEFAULT_TIMEOUT is an object(). In other words, it's an "object object". Also, that's not from the docstring but the call signature. The function doesn't have a docstring. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] group txt files by month
Hello All, it has been a few months since I have used this and I have only just realised I am having problems with leap years. each time I get to February of a leap year my program stops, therefore I have attributed it to my code not accounting for leap years. Is there a simple way to fix my code (below) to account for leap years? Thanks stop_month = datetime(2011, 12, 31) month = datetime(2011, 01, 01) while month < stop_month: accumulate_month(month.year, month.month) month += timedelta(days=32) month = month.replace(day=01) On Wed, Apr 11, 2012 at 2:09 PM, questions anon wrote: > Thank you for this response it was a tremedous help. > It still took me awhile to work it all out and thought I would post what > worked for me. > Thanks again > > GLOBTEMPLATE = r"e:/rainfall-{year}/r{year}{month:02}??.txt" > > > def accumulate_month(year, month): > files = glob.glob(GLOBTEMPLATE.format(year=year, month=month)) > monthlyrain=[] > for ifile in files: > f=np.genfromtxt(ifile,skip_header=6) > monthlyrain.append(f) > print "year-month: ",year,"-",month, ", maximum: ", > np.max(monthlyrain), "minimum: ", np.min(monthlyrain), "mean: ", > np.mean(monthlyrain) > > stop_month = datetime(2011, 12, 31) > month = datetime(2011, 01, 01) > > while month < stop_month: > accumulate_month(month.year, month.month) > month += timedelta(days=32) > month = month.replace(day=01) > > > > > On Thu, Apr 5, 2012 at 4:57 PM, Peter Otten <__pete...@web.de> wrote: > >> questions anon wrote: >> >> > I have been able to write up what I want to do (using glob) but I am not >> > sure how to loop it or simplify it to make the script more efficient. >> > I am currently: >> > -grouping the same months in a year using glob >> > -opening the files in a group and combining the data using a list >> > -finding max, min etc for the list and printing it >> > >> > I need to do this for many years and therefore many months so really >> need >> > a way to make this more efficient. >> > Any feedback will be greatly appreciated >> > >> > MainFolder=r"E:/rainfall-2011/" >> > OutputFolder=r"E:/test_out/" >> > r201101=glob.glob(MainFolder+"r201101??.txt") >> > r201102=glob.glob(MainFolder+"r201102??.txt") >> > r201103=glob.glob(MainFolder+"r201103??.txt") >> > >> > rain201101=[] >> > rain201102=[] >> > rain201103=[] >> > monthlyrainfall=[] >> > >> > for ifile in r201101: >> > f=np.genfromtxt(ifile, skip_header=6) >> > rain201101.append(f) >> > >> > for ifile in r201102: >> > f=np.genfromtxt(ifile, skip_header=6) >> > rain201102.append(f) >> > >> > for ifile in r201103: >> > f=np.genfromtxt(ifile, skip_header=6) >> > rain201103.append(f) >> > >> > print "jan", np.max(rain201101), np.min(rain201101), >> np.mean(rain201101), >> > np.median(rain201101), np.std(rain201101) >> > print "feb", np.max(rain201102), np.min(rain201102), >> np.mean(rain201102), >> > np.median(rain201102), np.std(rain201102) >> > print "mar", np.max(rain201103), np.min(rain201103), >> np.mean(rain201103), >> > np.median(rain201103), np.std(rain201103) >> >> Strip the code down to one month >> >> > r201103=glob.glob(MainFolder+"r201103??.txt") >> > rain201101=[] >> > for ifile in r201101: >> > f=np.genfromtxt(ifile, skip_header=6) >> > rain201101.append(f) >> >> >> then turn it into a function, roughly >> >> GLOBTEMPLATE = "e:/rainfall-{year}/r{year}{month:02}??.txt" >> def accumulate_month(year, month): >>files = glob.glob(GLOBTEMPLATE.format(year=year, month=month)) >># read files, caculate and write stats >> >> and finally put it into a loop: >> >> from datetime import date, timedelta >> stop_month = date(2012, 4, 1) >> month = datetime(2011, 1, 1) >> while month < stop_month: >>accumulate_month(month.year, month.month) >>month += timedelta(days=32) >>month = month.replace(day=1) >> >> >> >> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] group txt files by month
questions anon wrote: > Hello All, it has been a few months since I have used this and I have only > just realised I am having problems with leap years. each time I get to > February of a leap year my program stops, Does it throw an exception (if so, post the traceback) or does it just terminate? > therefore I have attributed it > to my code not accounting for leap years. Is there a simple way to fix my > code (below) to account for leap years? > stop_month = datetime(2011, 12, 31) > month = datetime(2011, 01, 01) Hm, 2011 is not a leap year. > while month < stop_month: > accumulate_month(month.year, month.month) > month += timedelta(days=32) > month = month.replace(day=01) Anyway, this piece of code should work the same for leap years and non-leap years. The problem must be in the code you are not posting (or in your data). PS: > month = datetime(2011, 01, 01) Stylistic note: numbers starting with 0 are interpreted as octals. It doesn't matter here, but don't get into the habit: >>> 010 == 10 False ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor