[Tutor] convert an integer number to string.
hi friend. i send you this email for say you you have a great project with the python correctos, i dont know if you can help me with one code i try to make functionality but not work i wish can you help me, thank you and than you again, to following the line with the error: for i in range (10): cmds.button(label ="button", + srt(i+1)) thank you dude. JP ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] convert an integer number to string.
On Sun, Feb 19, 2017 at 11:05:35PM -0300, Juan Pablo Valladares wrote: > hi friend. > > i send you this email for say you you have a great project with the python > correctos, i dont know if you can help me with one code i try to make > functionality but not work i wish can you help me, thank you and than you > again, to following the line with the error: > > for i in range (10): > cmds.button(label ="button", + srt(i+1)) I see two errors: You write "srt" instead of str. Comma after "button" is not needed. cmds.button(label ="button" + srt(i+1)) may be better. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] convert an integer number to string.
On 20/02/17 09:36, Steven D'Aprano wrote: > Comma after "button" is not needed. > > cmds.button(label ="button" + srt(i+1)) > > may be better. and cmds.button(label ="button" + str(i+1)) better still :-) -- 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] Creating tables in Tkinter
On 19/02/17 16:18, Pooja Bhalode wrote: > Hi, > > I am trying to create a simple table. But I was wondering how do I get the > title of the table to span over multiple columns in the first row. > Code: > > from Tkinter import * > > root = Tk() > root.geometry("700x500") > Label(root, text = "Table 1").grid(row = 0, column = 0, sticky = W) grid has many attributes, you can see them using the help() function: - Help on function grid_configure in module tkinter: grid_configure(self, cnf={}, **kw) Position a widget in the parent widget in a grid. Use as options: column=number - use cell identified with given column (starting with 0) columnspan=number - this widget will span several columns in=master - use master to contain this widget in_=master - see 'in' option description ipadx=amount - add internal padding in x direction ipady=amount - add internal padding in y direction padx=amount - add padding in x direction pady=amount - add padding in y direction row=number - use cell identified with given row (starting with 0) rowspan=number - this widget will span several rows sticky=NSEW - if cell is larger on which sides will this widget stick to the cell boundary - Notice the columnspan option. set it to the number of columns in your table. -- 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] Resources/Books for teaching OOP in Python and Tkinter
On 19/02/17 16:34, Marie Shaw via Tutor wrote: > I am a teacher of 16-18 year olds. > I now need to teach them OOP using Python, > and GUI programming using Python. Those are two different topics, although most GUIs are easier if used with OOP. However, most tutorials (including mine) teach the basic syntax and usage of OOP so I'm not sure what extra information you need. It may e that a basic OOP text would be better - something like Timothy Budd's excellent intro(which uses Java) or even "UML Distilled" by Fowler which uses the UML design language. These both show how classes and objects should be used rather than just focussing on the syntax. As for GUI programming, if we assume you stick with Tkinter for now as it comes with Python and, although limited, is easy to learn, there are several options. The Tkinter page in the official documentation gives several online links. For books there are a few. The massive "Programming Python" tome by Lutz has about 400 pages dedicated to Tkinter. My own books(and web tutor) both have a (much shorter) chapter on it. Several other tutorials cover it too: Python, How to program by Dietel Teach Yourself Python in 24 hours and, if you can find it, Python & Tkinter programming by Grayson goes into great detail. HTH -- 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] Resources/Books for teaching OOP in Python and Tkinter
On 19/02/2017 16:34, Marie Shaw via Tutor wrote: I am a teacher of 16-18 year olds. Since September, my classes have been learning to program in Python, using all of the basics in console mode. I now need to teach them OOP using Python, and GUI programming using Python. Please could someone one point me in the direction of a good book, or some good teaching resources. I already have Python for the Absolute Beginner, by Michael Dawson, and Python in Easy Steps, by Michael McGrath. I like these books and have covered the relevant chapters in them. However, I need to learn more. Have you tried the Computing At School forums, Marie? (I assume you're UK-based from your address and the fact that you're teaching Python in Years 11-13). There are quite a few resources there already, but you can always start a thread in, eg, the Secondary Education forum. Here are a couple of links, but you'll need to have registered with CaS to view them. http://community.computingatschool.org.uk/search/resources?action=search&controller=search&query=tkinter&utf8=%E2%9C%93 http://community.computingatschool.org.uk/forums/23 Also, see GUI Zero by a former teacher who now works with the RPi Foundation: https://codeboom.wordpress.com/2017/01/07/gui-zero-making-python-guis-really-simple/ TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Resources/Books for teaching OOP in Python and Tkinter
On Sun, Feb 19, 2017 at 10:34 AM, Marie Shaw via Tutor wrote: > I am a teacher of 16-18 year olds. Since September, my classes have been > learning to program in Python, using all of the basics in console mode. > I now need to teach them OOP using Python, and GUI programming using Python. > Please could someone one point me in the direction of a good book, or some > good teaching resources. > I already have Python for the Absolute Beginner, by Michael Dawson, and > Python in Easy Steps, by Michael McGrath. I like these books and have covered > the relevant chapters in them. However, I need to learn more. There is a sequel to the "Absolute Beginner" book, but by a different author. It purports to go into more depth on OOP than the first book. "More Python Programming for the Absolute Beginner" by Jonathan S. Harbour: https://www.amazon.com/More-Python-Programming-Absolute-Beginner/dp/1435459806 It continues doing game programming using straight Pygame instead of that special package (Live Wires?) used in the first book. I bought the book once upon a time, but never used it, so I cannot vouch for how well it does anything. As for Tkinter/tkinter (Py2/Py3) I have yet to find a dedicated resource I like. The two books mentioned by Alan I own and use. "Python and Tkinter Programming" by Grayson is Python 2-based and is hard to follow, but has an excellent reference section and many examples. But so far the best in my mind seems to be "Programming Python" by Lutz, which is Python 3-based. He does a much better job explaining things; however, he is assuming you are fairly competent in basic Python, that is, it is a sequel to his other massive tome, "Learning Python". Online resources for tkinter are fairly plentiful. -- boB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Matplotlib in Tkinter
Hi, Another issue, in this that is happening which is far more important from the perspective that I am looking at, is that when I click the button twice, two graphs get created one below the other. I tried adding a delete("all") statement as shown below. Code: def Submitplot(): print "Create plot" print concsim.get() f = Figure(figsize = (5,5), dpi = 80) canvas = FigureCanvasTkAgg(f, simroot) canvas.get_tk_widget().delete("all") a = f.add_subplot(111) a.plot([1,2,3,4,5],[10,11,12,14,15]) canvas.show() canvas.get_tk_widget().pack(side = TOP) toolbar = NavigationToolbar2TkAgg(canvas, simroot) toolbar.update() canvas._tkcanvas.pack(side = TOP) Button(simroot, text = "Submit and Plot", command = Submitplot).pack(side = TOP) But this still does not clear the earlier made canvas and creates another graph at the bottom. Can someone please tell me what I am doing wrong here? I would really appreciate it. I have also added the image as to how the two plots look like. [image: Inline image 1] Thankyou On Sun, Feb 19, 2017 at 2:36 PM, Pooja Bhalode wrote: > Hi, > > I am trying to create a graph in Tkinter window. And following is a snipet > of the code. > > Code: > simroot = Toplevel(root) > simroot.title("Simulation of experiments") > Label(simroot, text = "Displaying concentration profiles with respect to > time:").pack(side = TOP) > > Label(simroot, text = "Select the experiments to be displayed: > ").pack(side = TOP) > optionexp = ['Experiment 1', 'Experiment 2', 'Experiment 3', 'Experiment > 4', 'Experiment 5'] > expsim = StringVar() > dropexp = OptionMenu(simroot, expsim, *optionexp) > dropexp.pack(side = TOP) > dropexp.config(width = 15) > > # Row 1 would print the name of the experiment selected and the species > displayed would be in row3. > Label(simroot, text = "Select concentration species:").pack(side = TOP) > concsim = StringVar() > optionlistsim = ['A', 'B', 'C', 'D', 'E'] > dropsim = OptionMenu(simroot, concsim, *optionlistsim) > dropsim.pack(side = TOP) > dropsim.config(width = 8) > Label(simroot, text = "").pack(side = LEFT) > > def Submitplot(): > print "Create plot" > > f = Figure(figsize = (5,5), dpi = 80) > a = f.add_subplot(111) > a.plot([1,2,3,4,5],[10,11,12,14,15]) > > canvas = FigureCanvasTkAgg(f, simroot) > canvas.show() > canvas.get_tk_widget().pack(side = BOTTOM) > > toolbar = NavigationToolbar2TkAgg(canvas, simroot) > toolbar.update() > canvas._tkcanvas.pack(side = BOTTOM) > Button(simroot, text = "Submit and Plot", command = Submitplot).pack(side > = BOTTOM) > > Here, the output comes as: > [image: Inline image 1] > The problem is I am not able to use grid layout instead of pack (used > here). I want to place the text to the left, top side in the window. > > Also, when I hover the mouse over the figure and the x and y values are > shown, it flickers really fast and the white space in the Tkinter window > turns black when it flickers. Can someone please tell me what the issue > could be? Also, the toolbar should have been at the bottom but it shows up > at the top. > > I am using pack in this Toplevel of the main root whereas in the rest of > the code, I am using grid layout. I switched to pack for this > snipet because I could not figure out how grid would work for this part. > > Can someone please let me know how to correct these issues? > Thankyou so much. > > Pooja > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Wedscraping Yahoo API
Hi, I keep getting the following error as I am new to programming and I am following a tutorial and I am using Python 3.6. Can you please point me in the right direction as to what I am doing wrong. This is code I am running import datetime as dtimport matplotlib.pyplot as pltfrom matplotlib import style#from matplotlib.finance import candlestick_ohlcimport matplotlib.dates as mdatesimport pandas as pdimport pandas_datareader.data as webimport bs4 as bsimport pickleimport requestsimport osimport csvimport numpy as npimport time style.use('ggplot') def save_tsx_tickers(): resp = requests.get('http://web.tmxmoney.com/indices.php?section=tsx&index=%5ETSX') soup = bs.BeautifulSoup(resp.text, "lxml") table = soup.find('table', {'class': 'indices-table'}) tickers = [] for row in table.findAll('tr')[1:]: ticker = row.findAll('td')[1].text tickers.append(ticker.replace(".","-") + ".TO") with open("tsxtickers.pickle", "wb") as f: pickle.dump(tickers, f) #print(tickers) return tickers def get_data_from_yahoo(reload_tsx = False): if reload_tsx: tickers = save_tsx_tickers() else: with open("tsxtickers.pickle", "rb") as f: tickers = pickle.load(f) if not os.path.exists('stock_dfs'): os.makedirs('stock_dfs') start = dt.datetime(2000, 1, 1) end = dt.datetime(2016, 12, 31) for i in tickers: if not os.path.exists('stock_dfs/{}.csv'.format(i)): time.sleep(2) df = web.DataReader(i, 'yahoo', start, end) df.to_csv('stock_dfs/{}.csv'.format(i)) else: print('Already have {}'.format(i)) However, I keep getting this error. Please help in identifying the problem. Thank you. Traceback (most recent call last): File "", line 1, in get_data_from_yahoo() File "C:\Users\Joe\Desktop\joe\Tutorial Python.py", line 50, in get_data_from_yahoo df = web.DataReader(i, 'yahoo', start, end) File "C:\Users\Joe\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\data.py", line 116, in DataReader session=session).read() File "C:\Users\Joe\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\yahoo\daily.py", line 76, in read df = super(YahooDailyReader, self).read() File "C:\Users\Joe\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\base.py", line 155, in read df = self._read_one_data(self.url, params=self._get_params(self.symbols)) File "C:\Users\Joe\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\base.py", line 74, in _read_one_data out = self._read_url_as_StringIO(url, params=params) File "C:\Users\Joe\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\base.py", line 85, in _read_url_as_StringIO response = self._get_response(url, params=params) File "C:\Users\Joe\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\base.py", line 120, in _get_response raise RemoteDataError('Unable to read URL: {0}'.format(url))pandas_datareader._utils.RemoteDataError: Unable to read URL: http://ichart.finance.yahoo.com/table.csv?s=OTEX.TO&a=0&b=1&c=2000&d=11&e=31&f=2016&g=d&ignore=.csv ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Matplotlib in Tkinter
On 20/02/17 14:54, Pooja Bhalode wrote: > Another issue, in this that is happening which is far more important from > the perspective that I am looking at, is that when I click the button > twice, two graphs get created one below the other. > > I tried adding a delete("all") statement as shown below. I don't use matplotlib with Tkinter so can't comment but matplotlib is not part of the standard library. Therefore it is technically off-topic for this list, although I know some folks here do use it. However, you might get a better response on the SciPy/Matplot lib support forums where I'm sure there will be many more users hanging out. -- 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] Wedscraping Yahoo API
Please post in plain text. Formatting is very important in Python and RTF or HTML tend to get scrambled in transit making your code and error hard to read. Thanks Alan G. On 20/02/17 14:32, Joe via Tutor wrote: > Hi, > I keep getting the following error as I am new to programming and I am > following a tutorial and I am using Python 3.6. Can you please point me in > the right direction as to what I am doing wrong. This is code I am running > import datetime as dtimport matplotlib.pyplot as pltfrom matplotlib import > style#from matplotlib.finance import candlestick_ohlcimport matplotlib.dates > as mdatesimport pandas as pdimport pandas_datareader.data as webimport bs4 as > bsimport pickleimport requestsimport osimport csvimport numpy as npimport time > style.use('ggplot') > def save_tsx_tickers():resp = > requests.get('http://web.tmxmoney.com/indices.php?section=tsx&index=%5ETSX') > soup = bs.BeautifulSoup(resp.text, "lxml")table = soup.find('table', > {'class': 'indices-table'})tickers = []for row in > table.findAll('tr')[1:]:ticker = row.findAll('td')[1].text > tickers.append(ticker.replace(".","-") + ".TO") > with open("tsxtickers.pickle", "wb") as f:pickle.dump(tickers, f) > #print(tickers)return tickers > def get_data_from_yahoo(reload_tsx = False):if reload_tsx:tickers > = save_tsx_tickers()else:with open("tsxtickers.pickle", "rb") as > f:tickers = pickle.load(f) > if not os.path.exists('stock_dfs'):os.makedirs('stock_dfs') > start = dt.datetime(2000, 1, 1)end = dt.datetime(2016, 12, 31) > for i in tickers:if not > os.path.exists('stock_dfs/{}.csv'.format(i)):time.sleep(2) > df = web.DataReader(i, 'yahoo', start, end) > df.to_csv('stock_dfs/{}.csv'.format(i))else: > print('Already have {}'.format(i)) > > > However, I keep getting this error. Please help in identifying the problem. > Thank you. > > > Traceback (most recent call last): File "", line 1, in > get_data_from_yahoo() File "C:\Users\Joe\Desktop\joe\Tutorial Python.py", > line 50, in get_data_from_yahoodf = web.DataReader(i, 'yahoo', start, > end) File > "C:\Users\Joe\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\data.py", > line 116, in DataReadersession=session).read() File > "C:\Users\Joe\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\yahoo\daily.py", > line 76, in readdf = super(YahooDailyReader, self).read() File > "C:\Users\Joe\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\base.py", > line 155, in readdf = self._read_one_data(self.url, > params=self._get_params(self.symbols)) File > "C:\Users\Joe\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\base.py", > line 74, in _read_one_dataout = self._read_url_as_StringIO(url, > params=params) File "C:\Users\Joe\AppData\Local \Programs\Python\Python36-32\lib\site-packages\pandas_datareader\base.py", line 85, in _read_url_as_StringIOresponse = self._get_response(url, params=params) File "C:\Users\Joe\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\base.py", line 120, in _get_responseraise RemoteDataError('Unable to read URL: {0}'.format(url))pandas_datareader._utils.RemoteDataError: Unable to read URL: http://ichart.finance.yahoo.com/table.csv?s=OTEX.TO&a=0&b=1&c=2000&d=11&e=31&f=2016&g=d&ignore=.csv > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Wedscraping Yahoo API
Hi Joe, On Mon, Feb 20, 2017 at 6:32 AM, Joe via Tutor wrote: > Hi, > I keep getting the following error as I am new to programming and I am > following a tutorial and I am using Python 3.6. Can you please point me in > the right direction as to what I am doing wrong. You have made an assumption that you have done something wrong. Although this might be true, when we program anything substantial that interacts with other remote services, failures can happen anywhere in that chain, be it problems in third-party libraries, to problems with the servers, to even interference from the low-level network! Read the error message carefully, especially the last part: ## RemoteDataError: Unable to read URL: http://ichart.finance.yahoo.com/table.csv?s=OTEX.TO&a=0&b=1&c=2000&d=11&e=31&f=2016&g=d&ignore=.csv ## It says that it can't read the content at that URL. So there are a few possibilities. Perhaps there is a problem in your code. However, you mention that this script is web-scraping Yahoo. Web-scraping is known to be an extremely fragile endeavor, because it introduces factors entirely out of your control: * Perhaps that URL is wrong. * Perhaps the page is no longer available. * Perhaps the page structure has changed. * Perhaps the page is available sometimes, but the server recognizes that it is being scraped for content, and so returns an error response occasionally as a way to discourage scraping. * Perhaps your network is injecting content that breaks parsing. (The last is not as crazy as it sounds. See: https://arstechnica.com/tech-policy/2014/09/why-comcasts-javascript-ad-injections-threaten-security-net-neutrality/. A HTTPS-only web can't come soon enough.) Web scraping introduces all this uncertainty, making it a mess even for professional programmers. For these reasons, I contend that web scraping is a very bad example for introductory beginner programming. It's also usually a very bad idea for professional programmers too. Without a strong fundamental background, it's way too easy for a beginner to learn superstitious beliefs in that kind of environment, because too many things can happen that are outside of your control. You mention that you're new to programming. You might want to try a tutorial that doesn't depend so much on the external world. I would strongly recommend not continuing with this example, and go into something like: https://wiki.python.org/moin/BeginnersGuide/Programmers Have you taken a look at these tutorials? One of them might be better suited for you. Hope that makes sense; good luck! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Please explain part of this code
On Wed, Feb 15, 2017 at 5:37 PM, Jim wrote: > I don't recall ever seeing this before. What is this technique called? I've heard picking which function to call sometimes called "dispatching", and picking which function to call based on functions held in a dictionary called "dictionary dispatch", or "dictionary based dispatching". I think this is in contrast to a C technique called "table dispatching". A google search for the phrase "python dictionary dispatch" should get lots of hits talking about the technique (I had to include "python" otherwise google kept trying to give me the dictionary definition of the word dispatch). Jerry ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor