Re: [Tutor] General question rgrd. usage of libraries
Hum i also suggest you get more experience with python think of a project and learn while doing it. thus you'll get motivation while at the same time doing something useful which you could reuse in the future. else, me for bs4 i googled what i needed. I also put an increasing variable to ease web scraping tasks. like var =0 ... print(var, element) also, i suggest you decode to unicode as you'll get crazy hex stuffs if you don't .decode("utf-8") i scrape websites written in french, so i always need unicode. else the .text is very helpful like 'p' gives you the element but 'p.text' gives you the content To find suitable libraries i suggest you become good at doing the desired task by hand as far as possible, so you'll know your job well. Then you identify boring, impossible or tiring tasks. Then you google like .. python module or just python how to and see how they did it or what module they used to do it. Hope it helps, Abdur-Rahmaan Janhangeer, Mauritius On 6 May 2017 00:56, "Jim"wrote: > On 05/05/2017 08:45 AM, Rafael Knuth wrote: > >> Hi there, >> >> I just recently learned how to build a basic web scraper with Python >> 3.5 (I am learning Python for data analytics purposes). Being new to >> coding, I have a question: >> >> How do I know which libraries I need to perform a certain task? >> For example, in case of this web scraper (which I built with help of a >> tutorial on YouTube) I need to have urrlib and Beautiful Soup >> >> import urllib >> import urllib.request >> from bs4 import BeautifulSoup >> >> theurl = "https://twitter.com/rafaelknuth; >> thepage = urllib.request.urlopen(theurl) >> soup = BeautifulSoup(thepage, "html.parser") >> >> print(soup.title.text) >> >> i = 1 >> for tweets in soup.findAll("div",{"class":"content"}): >> print(i) >> print(tweets.find("p").text) >> i = i + 1 >> >> Is there a way I can figure out which libraries I need when drafting my >> code? >> Can you share your experiences? Right now, if I wanted for example to >> populate a Google Sheet with my scraped web content - how would I know >> which libraries I would need to actually make this happen? I am trying >> wondering if there is a process to figure out what I exactly need >> library-wise. >> >> >> > There is a Python API to google sheets but when I had a look, it seemed > fairly complex. I haven't tried it yet but depending on what you need to do > this library may be what you need: > https://pypi.python.org/pypi/gspread. > > Regards, Jim > > > ___ > 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
[Tutor] selenium, automated testing and python
Sorry i'm a bit new to automated testing. I have explored python wide and deep but can someone just tell me why as a coder i need automated testing? i have tried some googling but the explanations are a bit crazy. thanks. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tkinter layout question
for entering digits on the canva i think better create a sort of sudoku generator and display it on the canva in a create_text object. On 20 Apr 2017 05:24, "Phil"wrote: > I'm looking for ideas here. > > A working solution for my sudoku solver is a 9 x 9 grid of entry boxes but > it looks a bit basic. So I created a 9 x 9 grid on a canvas which looks > much better. I can display digits in the centre of the squares but entering > the digits from the keyboard seems to be beyond me. I experimented with > entering a digit at the mouse location but it all seems to be too > complicated. Perhaps someone can offer a repetitively simple solution? > > A second experiment involved the earlier grid of entry boxes but with a > space between every third row and column. This seems to be more achievable, > eventually. > > Something along these lines: > > for i in range(9): > if i % 4 == 0: > place a blank text label > else: > place an entry box > > So, how might I enter digits into a grid on a canvas or how could I create > a space between a grid entry boxes? > > -- > Regards, > Phil > ___ > 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] bracket issue
-- Forwarded message -- From: "Palm Tree" <timeofsa...@gmail.com> Date: 16 Apr 2017 10:07 Subject: Re: [Tutor] bracket issue To: "Peter Otten" <__pete...@web.de> Cc: Ok thanks for the answers. Perfect. Just to clarify why i wanted recursion was that well coming to compiler theory, i created a python-based language called newB it allows you to define your own keywords but don't abuse like you can configure if to cheese cheese x == 4: coming to recursion well i currently use eval() so everything ok i don't have to worry about brackets but i want to write my own parser. a top down parser for expressions. you can also view the lang here: http://wp.me/p7UB6x-oV thanks for the answers once more On 15 Apr 2017 18:46, "Peter Otten" <__pete...@web.de> wrote: > Palm Tree wrote: > > > hi all. i'm trying to write a simple program. i'm using python 3.4 > > > > let us say i have > > > > s="2*3+3(8-4(5+6+9))+2+3+3(4/4)" > > > > i want to find expression enclosed in brackets. > > > > i want outputs to be like: > > (8-4(5+6+9)) > > (5+6+9) > > (4/4) > > note : i'd like an answer involving recursion if possible > > No recursion, but a stack managed manually: > > >>> s = "2*3+3(8-4(5+6+9))+2+3+3(4/4)" > >>> stack = [] > >>> for i, c in enumerate(s): > ... if c == "(": > ... stack.append(i) > ... elif c == ")": > ... print(s[stack.pop():i+1]) > ... > (5+6+9) > (8-4(5+6+9)) > (4/4) > > The order is determined by the closing parenthesis, you could sort if you > don't want that. > > I did not find a convincing translation using recursion, but I'll give one > anyway: > > def find_closing(s): > i = c = None > pairs = enumerate(s) > def step(start=None): > nonlocal i, c > for i, c in pairs: > if c == "(": > step(i) > elif c == ")": > if start is not None: > print(s[start:i+1]) > return > step() > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?
On 16 Apr 2017 10:01, "Palm Tree" <timeofsa...@gmail.com> wrote: Sorry for late reply. We usually organise python challenges. Once we organise a gui calculator challenge. You can view the submissions on my blog here: https://abdurrahmaanjanhangeer.wordpress.com/gui-py- calculator-challenge-19-1-17/ On 16 Apr 2017 09:50, "Alex Kleider" <aklei...@sonic.net> wrote: > On 2017-04-15 01:04, Alan Gauld via Tutor wrote: > > > >> Finally, if you can find a copy of my recent book "Python Projects" >> there is a rolling project within that which demonstrates how >> the same logic code can be used to build a CLI, a GUI and a >> Web app. [ In fact it goes even further by demonstrating how >> to break an app into 3 tiers - data, logic and UI - which >> is industry best practice, but usually overkill for small >> projects.] >> > > Thanks, Alan, for the guidance. As it happens, I have a copy of your > Python Projects" book- time to get it off the shelf and have a closer look! > Alex > ___ > 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
[Tutor] bracket issue
hi all. i'm trying to write a simple program. i'm using python 3.4 let us say i have s="2*3+3(8-4(5+6+9))+2+3+3(4/4)" i want to find expression enclosed in brackets. i want outputs to be like: (8-4(5+6+9)) (5+6+9) (4/4) i've tried where denotes an indentation level : #first part sbracket=[ ] ebracket=[ ] for i in range(len(s)): global sbracket global ebracket if f[i] == "(": sbracket.append(i) elif f[i] == ")": ebracket.append(i) #second part for i in range(len(sbracket)): print(f[sbracket[i]:ebracket[i]]) however, the above code works well as long as there are no nested brackets like s="(1+2)(2+3)" but fails as soon as s="((3+2))2" prior to that i wrote it like: for i in range(len(f)): if f[i] == "(": sbracket.append(i) for x in range(len(f)): if f[i+x]==")": ebracket.append(x) break but that too failed to output correctly note : i'd like an answer involving recursion if possible ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor