Re: [Tutor] How to write a function which reads files

2018-08-07 Thread Chris Warrick
unction name, since the latter is typically used for classes, and perhaps call it read_file to better describe it? -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subs

Re: [Tutor] A Question Regarding the Documentation Format

2017-09-24 Thread Chris Warrick
s indicates the return type: input() returns a string. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] subprocess.getstatusoutput : UnicodeDecodeError

2017-09-22 Thread Chris Warrick
end on tail being available (it’s not on Windows), and there may also be version differences. Instead of tail, you should use Python’s standard file operations (open()) to accomplish your task. [advertisement] Extra reading on security (shell=False) and the necessity of calling subprocesses: https:/

Re: [Tutor] How is database creation normally handled?

2017-09-10 Thread Chris Warrick
ressive enhancement: adding more features that need extra columns I didn’t think of first. Or removing features that weren’t cool. Or restoring them the next day. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 ___ Tutor maillist - Tutor@

Re: [Tutor] Help

2017-09-06 Thread Chris Warrick
.keys()) search_key = str(input("> ")) if search_key in data: print(search_key, ":", data[search_key]) else: print("Not in dictionary.") (I also cleaned it up a little) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Python 3 for Beginners was: (Re: intro book for python)

2017-09-03 Thread Chris Warrick
started playing. Half > an hour, maybe forty five minutes later and my little project did what I was > trying to do. This was before I really knew any python; the language was > that clean and easy to learn. You can still do that with Python 3. (Although you’ll be better off using asyncio

Re: [Tutor] intro book for python

2017-09-01 Thread Chris Warrick
teapress.com/wp/think-python-2e/ [2] https://automatetheboringstuff.com/ [3] https://learnpythonthehardway.org/book/nopython3.html [4] https://eev.ee/blog/2016/11/23/a-rebuttal-for-python-3/ -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 _

Re: [Tutor] Percentage of installations without setuptools (Was if __name__=='__main__' ...)

2017-08-11 Thread Chris Warrick
[snip some unrelated stuff] dependency: python3-pip provider: python3-pip-9.0.1-9.fc26.noarch dependency: python3-setuptools provider: python3-setuptools-36.2.0-1.fc26.noarch On other distributions, it usually isn’t, although many users will eventually end up with a copy. -- Chris Warri

Re: [Tutor] setup.py "script" vs "console_scripts" Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-10 Thread Chris Warrick
On 9 August 2017 at 23:15, Steven D'Aprano wrote: > On Tue, Aug 08, 2017 at 12:56:56PM +0200, Chris Warrick wrote: > >> While setuptools is not officially part of the stdlib, > > This is the critical factor. How can you use *by default* something that > is *NOT* supplied

Re: [Tutor] setup.py "script" vs "console_scripts" Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-08 Thread Chris Warrick
ns that at least that many use setuptools; sometimes with a distutils fallback, but often without one. Moreover, many of the packages without wheels use setuptools as well. The sane default choice is entry_points. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 __

Re: [Tutor] setup.py "script" vs "console_scripts" Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-04 Thread Chris Warrick
ystems > * the ability to automatically generate Windows command line executables at > installation time rather than needing to prebuild them And, as eryk sun mentioned, recent Python 2.7 and 3.4 versions ship setuptools and pip, via the ensurepip module. -- Chris Warrick <https://chris

Re: [Tutor] setup.py "script" vs "console_scripts" Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-03 Thread Chris Warrick
cript" vs "console_scripts entry-point"? Simple: `scripts` are legacy. `entry_points` are the new thing. There’s also a third approach: gui_scripts entry_points, which work the same way on Linux/*nix, but on Windows, it means that running your script by opening the created .exe fi

Re: [Tutor] if __name__=='main' vs entry points: What to teach new comers?

2017-08-01 Thread Chris Warrick
e akin to shell scripts, using just entry_points makes stuff harder, because you need to install the code (and write a setup.py), as opposed to just putting the script somewhere in $PATH. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 __

Re: [Tutor] Recommended Python Compiler

2017-07-31 Thread Chris Warrick
ging (tracebacks!) On the other hand, some of the better editors (eg. Visual Studio Code) provide .zip packages that do not require installation and can even run off a USB stick. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 __

Re: [Tutor] Can a virtual environment be renamed?

2017-04-16 Thread Chris Warrick
On 16 April 2017 at 18:16, Jim wrote: > On 04/16/2017 10:10 AM, Chris Warrick wrote: >> >> On 16 April 2017 at 16:45, Jim wrote: >>> >>> My system python is 2.7.12 so I created a virtual environment using venu >>> to >>> run 3.5.2. I put it in

Re: [Tutor] Can a virtual environment be renamed?

2017-04-16 Thread Chris Warrick
gs? No. You need to delete your existing virtualenv and create a new one. You can just use `pip freeze > requirements.txt` in the old one and run `pip install -r requirements.txt` in the new one to ”move” all the packages you had. -- Chris Warrick <https://chriswarrick.c

Re: [Tutor] How to run a python script

2016-02-21 Thread Chris Warrick
DOS is not part of Windows NT/2000/XP and better, and rightfully so. [0]: In Windows 8?/10, available from the File menu. Otherwise: http://www.askvg.com/enable-open-command-window-here-option-in-context-menu-in-windows-vista/ -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 ___

Re: [Tutor] How to run a python script

2016-02-20 Thread Chris Warrick
ail.python.org/mailman/listinfo/tutor Please paste the full error message, and your complete source code. Also, make sure you are running the commands in the regular command prompt window, and not in a Python-specific one. Also, your scripts should not live in C:\Python27, because they might conflict wit

Re: [Tutor] AWS /Django/Apache/Python/Github

2016-02-13 Thread Chris Warrick
a Python application on a Linux server: https://chriswarrick.com/blog/2016/02/10/deploying-python-web-apps-with-nginx-and-uwsgi-emperor/ -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 ___ Tutor maillist - Tutor@python.org To unsubs

Re: [Tutor] What is the square brackets about?

2016-01-16 Thread Chris Warrick
what the 0th element of `loc` (`loc[0]`) is, and use it as an index for `thing` (`thing[…]`). -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http

Re: [Tutor] idle??

2016-01-14 Thread Chris Warrick
On 13 January 2016 at 21:49, Mark Lawrence wrote: > On 09/01/2016 10:38, Chris Warrick wrote: >> >> On 8 January 2016 at 20:07, bruce wrote: >>> >>> So, where does IDLE fit into this >> >> >> IDLE is a sad little “IDE”, which is really ugl

Re: [Tutor] idle??

2016-01-09 Thread Chris Warrick
nterpreter, and even have more features than IDLE. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] To FORMAT or not to

2016-01-03 Thread Chris Warrick
nt() with commas adds spaces between all entries, which might look bad (and it does in this example); the only way to prevent that is by setting `sep=`, but then you need to remember about a space after "visited" and around the ampersand… * Easy to localize (translate into

Re: [Tutor] Debugging in Python

2015-11-16 Thread Chris Warrick
thon or bpython. The correct fix is to exit() from the python3 shell and start it again. Alternatively, add some main code at the end of your file and use `python3 hlibert.py`: if __name__ == '__main__': hilbert(3) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 _

Re: [Tutor] command line list arguments

2015-11-07 Thread Chris Warrick
t; seen an example of this on the web). 1. NEVER use eval(). 2. Trying to pass Python code as arguments looks bad. Don’t do that. 3. Your issues with '' are caused by your shell. You would need to wrap your entire thing in quotes first, or use escaping. But instead, 4. Use argpa

Re: [Tutor] generate a list/dict with a dynamic name..

2015-09-27 Thread Chris Warrick
ct and use it — you can have arbitrary variable names just fine: things = {} a = "aabb" things[a] = [] PS. why are you creating a out of two strings? Why not just a = "aabb"? -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Python application with same name as its corresponding project

2015-07-31 Thread Chris Warrick
_ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor Don’t create custom bin/ scripts, use setuptools entry points. I described it on my blog: https://chriswarrick.com/blog/2014/0

Re: [Tutor] trouble with stringio function in python 3.2

2015-05-04 Thread Chris Warrick
his line — in that case, you can even drop the if/else and just use the same dictionary assignment for both Pythons. Just be warned that it applies to the entire file and can lead to problems. PS. There is no reason to use """multi-line strings""" in this case, regular "

Re: [Tutor] Decode and Encode

2015-01-28 Thread Chris Warrick
gt;>> p = "你好".decode('utf-8') >>> p u'\u4f60\u597d' However, this does not apply in Python 3. Python 3 defaults to Unicode strings, so you can do: >>> p = "你好" and have proper Unicode handling, assuming your system locale is set

Re: [Tutor] syntax error with raw input

2014-11-12 Thread Chris Warrick
_ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > In Python 3, raw_input() was renamed to input(). a = input("Write down your name: ") Note that input() is also a thing in Pyt

Re: [Tutor] Remove artca...@google.com from mailing list, PLEASE

2014-11-04 Thread Chris Warrick
Do it yourself at https://mail.python.org/mailman/listinfo/tutor . Besides, your email is @gmail.com, not @google.com. -- Chris Warrick <http://chriswarrick.com/> PGP: 5EAAEA16 ___ Tutor maillist - Tutor@python.org To unsubscribe or