Re: [Tutor] Regex/Raw String confusion
On 08/04/2016 03:27 AM, Alan Gauld via Tutor wrote: On 04/08/16 02:54, Jim Byrnes wrote: Is the second example a special case? phoneNumRegex = re.compile(r'(\(\d\d\d\)) (\d\d\d-\d\d\d\d)') I ask because it produces the same results with or without the ' r '. That's because in this specific case there are no conflicts between the regex escape codes and the Python escape codes. In other words Python does not treat '\(' or '\d' as special characters so it doesn't change the string passed to the regex. (It would be a different story if you had used, say, a '\x' or '\n' or '\b' in the regex.) In general you should proceed with caution and assume that there might be a Python escape sequence lurking in the regex and use raw just in case. Ok, thanks again. I understand what is going on now. Regards, Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SQLite Django
Forwarding to list. Please use REplyAll when responding to tutor messages. On 04/08/16 09:19, Trevor H wrote: > Hi Alan, > > Thank you for the reply. I'll try show the graphic as a website. Would > I have to make the data entries as a model in Django? > I'm not a Django expert so don;t know where you would put the code to generate the image. But based on usual MVC practice I'd assume it would be a model somewhere. However the image itself will just be a file on the server and would be stored in the same place as any other images such as logos etc. The key difference is that the image filename will need to be injected into your HTML template somehow and I assume you do that by linking a model variable to a marker in the template. Again I'm no Django expert I've only watched a few YouTube tutorials... > I'm new to this sorry for the newbie question. Newbie questions are what we are here for. Although Django specific issues might be better addressed to the Django list. But we will usually have a pop at them if they are not too Django specific. > I have to link all my data like so to give a plot. Just don't know how. > > SQLi command to join my tables: > To join all tables: > SELECT devices.id AS id, > macs.address AS mac, > oses.name AS os, > browsers.name AS browser > FROM devices > JOIN macs ON devices.mac = macs.id > JOIN oses ON devices.os = oses.id > JOIN browsers ON devices.browser = browsers.id; > Getting the data and generating the plot are two separate issues. You can experiment with the SQL using the SQLIte interpreter till you have a query that delivers what you need. If you don't already have it installed I strongly recommend doing so. Without knowing what you're trying to plot and what your schema looks like I can't really comment on the SQL -- 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] Help
CJ wrote: > Hi, > I’m coding a game for fun and i keep trying to run it but this keeps > showing up: > traceback (most recent call last): > File "/Volumes/name/box move thing(wed).py", line 13, in > player_img = PhotoImage(file="astronaut.png") > File > "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", > line 3394, in __init__ > Image.__init__(self, 'photo', name, cnf, master, **kw) > File > "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", > line 3350, in __init__ > self.tk.call(('image', 'create', imgtype, name,) + options) > _tkinter.TclError: couldn't open "astronaut.png": no such file or > directory > > Even though I have a file named “astronaut.png” I’ve tried a lot of things > if I could be helped that would be awesome. Print the working directory before the line creating the image: import os os.print(os.getcwd()) > player_img = PhotoImage(file="astronaut.png") Chances are that "astronaut.png" is in another directory. If so you have to provide the path to that directory, e. g. player_img = PhotoImage(file="images/astronaut.png") If the image is in the same directory as the script you can construct the path with import os image_folder = os.path.dirname(__file__) ... player_img = PhotoImage(file=os.path.join(image_folder, "astronaut.png")) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Regex/Raw String confusion
On 04/08/16 02:54, Jim Byrnes wrote: > Is the second example a special case? > > phoneNumRegex = re.compile(r'(\(\d\d\d\)) (\d\d\d-\d\d\d\d)') > > I ask because it produces the same results with or without the ' r '. That's because in this specific case there are no conflicts between the regex escape codes and the Python escape codes. In other words Python does not treat '\(' or '\d' as special characters so it doesn't change the string passed to the regex. (It would be a different story if you had used, say, a '\x' or '\n' or '\b' in the regex.) In general you should proceed with caution and assume that there might be a Python escape sequence lurking in the regex and use raw just in case. -- 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] Help
Hi, I’m coding a game for fun and i keep trying to run it but this keeps showing up: traceback (most recent call last): File "/Volumes/name/box move thing(wed).py", line 13, in player_img = PhotoImage(file="astronaut.png") File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 3394, in __init__ Image.__init__(self, 'photo', name, cnf, master, **kw) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 3350, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't open "astronaut.png": no such file or directory Even though I have a file named “astronaut.png” I’ve tried a lot of things if I could be helped that would be awesome. Thanks, Anonymous ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor