Re: # type: a
On Sun, 15 Sep 2019 at 16:53, Hongyi Zhao wrote: > > Hi, > > In pycharm, when I commented out the following line: > > # type: a > > The pycharm still told me that: > > Unresolved reference 'a' PyCharm interprets PEP 484 type annotations and type comments, as well as PEP 526 variable annotations. The comment you wrote is a type comment that says 'a' is the expected type of something. The 'type:' part is special here, `# foo: a` won’t trigger this warning. PyCharm expects stuff in type comments to exist, because otherwise, there’s no way to know what type you mean. Type comments are now best replaced by Python 3.6+ variable annotations, but the comments are still valid, and can be used in some contexts where annotations are not supported. https://www.python.org/dev/peps/pep-0484/#type-comments -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: sys.modules
On Thu, 21 Feb 2019 at 18:57, ast wrote: > > Hello > > Is it normal to have 151 entries in dictionary sys.modules > just after starting IDLE or something goes wrong ? > > >>> import sys > >>> len(sys.modules) > 151 > > Most of common modules seems to be already there, > os, itertools, random > > I thought that sys.modules was containing loaded modules > with import command only. sys.modules contains all modules that have been imported in the current session. Some of those imports happen in the background, without your knowledge — for example, because these modules are required by the interpreter itself, or are part of IDLE. The number you see depends on the environment (I got 530 in ipython3, 34 in python3, 45 in python2) and is not in any way important. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: preferences file
On Thu, 24 Jan 2019 at 20:50, Dave wrote: > > I'm doing a small application and want to add user preferences. Did > some googling to see if there are standard Python ways/tools, but it > seems not so much. My specific questions are: > > 1. Best practices for a user preference file/system? Put them in the appropriate config directory (see answer to Q3). Windows has the registry and macOS has User Defaults, but a custom format is fine, especially if you’re making something multi-platform. > 2. File format favored and why - ini, JSON, etc? If you want/expect humans to edit it, go with INI (configparser). Otherwise (if the editing is done via your app with a nice UI), JSON can express more than just key-value mappings, although there are no comments, and its strict syntax requirements can be problematic for non-programmers trying to edit the file. Randomly loading .py or pickle files can potentially be unsafe; writing .py files in an automated way is not trivial. I wouldn’t bother with any other formats, mainly since they are not supported in stdlib, although if you need human editing and more advanced structures, then maybe YAML/TOML (they aren’t as foolproof as INI though). > 3. File location? I'm using Ubuntu and I believe that the correct > location would be home/.config/ . What about Mac and Windows? https://pypi.org/project/appdirs/ -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Packages Survey
On Sat, 19 Jan 2019 at 01:22, Cameron Davidson-Pilon wrote: > > Hello! I invite you to participate in the Python Packages Survey - it takes > less than a minute to complete, and will help open source developers > understand their users' better. Thanks for participating! > > https://python-packages-survey.com/ The site says: > Completing the survey is as easy as running a Python script No, thanks. A better way to get meaningful results is to just create a good old web form, where you can ask people more detailed questions than just mining the installed package list. Also, even if you promise to filter out private packages, they *do* reach your server, and many people would prefer that didn’t happen. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Wikipedia on Python
On Tue, 16 Oct 2018 at 20:11, Chris Angelico wrote: > > On Wed, Oct 17, 2018 at 5:05 AM Spencer Graves > wrote: > >Beyond that, I'd like to encourage people on this list to review > > the Wikipedia article on "Python (programming language)",[1] especially > > the claim that "a package is a Python module with an __path__ > > attribute", which I added on 2018-09-24 to help me understand the > > distinction. > > > > You're welcome to put whatever you like into Wikipedia, but > personally, I don't think that particular piece of terminology is all > that helpful to the typical reader. Technical distinctions aren't > important to someone who's trying to find out what Python's all about, > or why s/he should learn the language. Seconded. This is not useful at all on Wikipedia. I took the liberty to remove this paragraph, because I don’t think anyone would find it useful; in fact, it would only confuse people. Here’s a diff for anyone interested in the original content: https://en.wikipedia.org/w/index.php?title=Python_(programming_language)&diff=prev&oldid=861064627 -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: My environment doesn't load
On Tue, 9 Oct 2018 at 11:18, wrote: > > Here are the ouput during sourcing: > > > [ftg @ localhost] [/var/www/ffablob] > > % source env-p3/bin/activate > > [ftg @ localhost] [/var/www/ffablob] > > % which python > > /usr/bin/python > > and if I run some of my code that import beautyfulsoup it fails (python > mycode.py), althoug running > directly ./env-p3/python3.5 mycode.py is working... Was the virtualenv copied between machines or directories? If yes: you can’t do that, you must create a new virtualenv in the desired location and install dependencies to it. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Connection refused when tryign to run bottle/flask web framweworks
On Mon, 20 Aug 2018 at 18:15, Νίκος wrote: > > Τη Δευτέρα, 20 Αυγούστου 2018 - 9:49:00 π.μ. UTC+3, ο χρήστης Miki Tebeka > έγραψε: > > If you're trying to access the machine from another machine, you need to > > change the host to '0.0.0.0'. 'localhost' is the internal interface. > > > > On Sunday, August 19, 2018 at 10:36:25 PM UTC+3, Νίκος wrote: > > > Hello, > > > > > > i just installed bottle and flask web frameworks in my CentOS environment > > > but i canno get it working even with the simpleste xample. The coonection > > > is refused always. > > > > > > from bottle import route, run, template > > > > > > @route('/hello/') > > > def index(name): > > > return template('Hello {{name}}!', name=name) > > > > > > run(host='localhost', port=8080) > > > > > > > > > Any ideas as to why i cannot access it? > > > I dont have sme firewall blocking the ports 8080 or 5000. > > > > > > Thank you. > > 0.0.0.0 is used when you want your app to lsiten to all available interfaces. > Even with that still i cannot access the hello app. You should avoid exposing the built-in web server to the Internet. Either way, are you sure you don’t have any firewall set up on the server? -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Fishing from PyPI ?
On Tue, 7 Aug 2018 at 00:52, Gregory Ewing wrote: > > Chris Warrick wrote: > > The unusual domain is a common staple of Mailchimp, which is an e-mail > > newsletter platform (it was used to mail out the announcement), and > > they replace all links with tracking ones in their list-manage.com > > domain. > > Sounds like you need to find a mail service that doesn't > screw around with the contents of your messages. This is > really quite obnoxious, IMO. For the record, I’m not in any way affiliated with the PyPA. I’m just linking to official resources that prove the legitimacy of these e-mails. As for finding a better host, it’s not easy. MailChimp, as annoying as they might be, has built up a good reputation with mail hosts* (of course, there are a bunch of other services that have such reputation as well.) However, if you send the e-mail yourself, and big mail hosts notice you have sent a ton of e-mail, they will probably consider you a spammer and make your life harder. Especially if your e-mail server is misconfigured in even the slightest way. * https://mailchimp.com/features/email-delivery/ -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Fishing from PyPI ?
On Mon, 6 Aug 2018 at 19:31, MRAB wrote: > > https://pypi.us18.list-manage.com/track/[snip] > If you want to be sure, ignore the links in the email, and check PyPI at > the URL that you know is correct. > > Given that the email says "https://pypi.us18.list-manage.com"; and PyPI > is at "https://pypi.org/";, it does look suspicious. > -- > https://mail.python.org/mailman/listinfo/python-list Those e-mails are legitimate. See [1] and [2]. The unusual domain is a common staple of Mailchimp, which is an e-mail newsletter platform (it was used to mail out the announcement), and they replace all links with tracking ones in their list-manage.com domain. (They also implement the GDPR in an anti-user/pro-spam fashion, but I digress.) [1]: https://status.python.org/incidents/nk7cyn2vh4wr [2]: https://github.com/pypa/warehouse/issues/3632 -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: PyCharm
On Sat, 21 Jul 2018 at 05:17, wrote: > > Win7 > > I was watching some tutorial videos on Python that recommended I use > PyCharm and it worked pretty well until I tried to use input. > > I found this: > https://youtrack.jetbrains.com/issue/PY-27891 > > It says.. > Pavel Karateev commented 10 Jan 2018 11:57 > Hi Calvin Broadus! I am sorry for the inconvenience, this is the > problem on PyCharm side, the fix is in progress, should be included in > the next minor update 2017.3.3, release candidate build is planned on > this week. > > Since I just installed the program yesterday, I assume that the fix > has not been implemented yet. > > Most of my practice programs I always just enter a set value for > inputs instead of taking inputs from the keyboard, but I would like to > pause so find out why my program is broken. > > Is there another way to insert a pause that will work with PyCharm? > -- > https://mail.python.org/mailman/listinfo/python-list How does it fail? What PyCharm version are you on? -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: ipython does not work with latest version of prompt-toolkit
On Sun, 3 Jun 2018 at 10:32, Cecil Westerhof wrote: > > When executing: > pip3 list --no-cache-dir --outdated > > I got: > prompt-toolkit 1.0.152.0.1wheel > PyGObject 3.28.23.28.3 sdist > youtube-dl 2018.5.30 2018.6.2 wheel > > So I executed: > pip3 install --upgrade prompt-toolkit PyGObject youtube-dl > > This gave: > Successfully installed PyGObject-3.28.3 prompt-toolkit-2.0.1 > youtube-dl-2018.6.2 > ipython 6.4.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but you'll > have prompt-toolkit 2.0.1 which is incompatible. > > And when I now execute ipython3, I get: > Traceback (most recent call last): > File "/usr/local/bin/ipython3", line 7, in > from IPython import start_ipython > File "/usr/local/lib/python3.5/dist-packages/IPython/__init__.py", line > 55, in > from .terminal.embed import embed > File > "/usr/local/lib/python3.5/dist-packages/IPython/terminal/embed.py", line 16, > in > from IPython.terminal.interactiveshell import TerminalInteractiveShell > File > "/usr/local/lib/python3.5/dist-packages/IPython/terminal/interactiveshell.py", > line 22, in > from prompt_toolkit.shortcuts import create_prompt_application, > create_eventloop, create_prompt_layout, create_output > ImportError: cannot import name 'create_prompt_application' > > When I now execute: > pip3 list --no-cache-dir --outdated > > I do not get output. So pip3 thinks everything is OK. > > How do I fix this? Or is the expected that ipython3 will be updated > shortly? Start by reading the warning from pip: > ipython 6.4.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but you'll > have prompt-toolkit 2.0.1 which is incompatible. To fix this, downgrade prompt-toolkit. `pip list --outdated` (not) having output isn’t a “good” or “bad” thing. prompt-toolkit v2 has changed its API from v1, and ipython doesn’t support the new one yet. Don’t randomly upgrade pip packages without knowing what the upgrade entails, especially if the version changed from 1.x to 2.x (x.y → x+1.y) — that usually means an API change and possible incompatibilities in dependent packages. Upgrading a tool like youtube-dl should be fine, and so should be a x.y.z → x.y.z+1 upgrade, but it’s still best to know what you’re doing. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: venv: make installed modules visible
On Tue, 1 May 2018 at 19:15, Paul Moore wrote: > Maybe you need --system-site-packages? DO NOT use this option. The entire point of a virtualenv is to be separate from both other environments and the system Python site-packages. The correct way to handle this is to install the modules using the virtualenv’s pip. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: I am a student studying Python in Korea. I found strange thing while studying through idle
On 9 March 2018 at 01:07, 노연수 wrote: > If you type print (" hello\ rpython ") into the python 3.7.0.b2, only the > python is printed and i learned it's a crystal. However, if you type print (" > hello\ rpython ") in the python 3.7.0.b2 idle, it is output as hellopython. I > wonder why it prints like this. I would appreciate your answer. > > I have attached the file so I would appreciate your reference. > -- > https://mail.python.org/mailman/listinfo/python-list In both cases, 'hellopython' is printed, only the behavior of the cursor changes. The `\r` means “move cursor to the start of the line” in some places, including Terminal/Command Prompt. But not everyone processes the backspace character — IDLE ignores it, as do many other text editors. Another important thing to note about \r is this: >>> print("python\rhi") hithon (PS. it’s better to use a stable version, especially when you’re learning. PPS. file attachments do not work on this list.) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16On 9 March 2018 at 01:07, 노연수 <mailto:clear0...@naver.com"; target="_blank">clear0...@naver.com> wrote:If you type print (" hello\ rpython ") into the python 3.7.0.b2, only the python is printed and i learned it's a crystal. However, if you type print (" hello\ rpython ") in the python 3.7.0.b2 idle, it is output as hellopython. I wonder why it prints like this. I would appreciate your answer. I have attached the file so I would appreciate your reference. -- https://mail.python.org/mailman/listinfo/python-list"; data-saferedirecturl="https://www.google.com/url?hl=en-GB&q=https://mail.python.org/mailman/listinfo/python-list&source=gmail&ust=1520708438742000&usg=AFQjCNGayj8GjRvThJd0aWdvjz6jUEPsgA"; rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-list -- Chris Warrick <https://chriswarrick.com/"; target="_blank">https://chriswarrick.com/>PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: read Unicode characters one by one in python2
On 24 February 2018 at 17:17, Peng Yu wrote: > Here shows some code for reading Unicode characters one by one in > python2. Is it the best code for reading Unicode characters one by one > in python2? > > https://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8#Python No, it’s terrible. So is the Python 3 version. All you need for both Pythons is this: import io with io.open('input.txt', 'r', encoding='utf-8') as fh: for character in fh: print(character) (and please make sure you need to read character-by-character first) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Getting "ValueError: need more than 1 value to unpack" while trying to read a value from dictionary in python
On 15 February 2018 at 12:07, Sum J wrote: > Below is my code. Here I want to read the "ip address" from s > > > s= ''' > Power On Enabled = On > State: connected > Radio Module: Unknown > noise: -097 > signalStrength: -046 > ip address: 192.168.75.147 > subnet mask: 255.255.255.0 > IPv4 address configured by DHCP > Mac Addr: ac:e2:d3:32:00:5a > Mode: infrastrastructure > ssid: Cloudlab > Channel: 1 > Regulatory: World Safe > Authencation: WPA2/PSK > Encryption: AES or TKIP > ''' > >s = s.replace("=",":") ># s = s.strip() >print s > > d = {} > for i in s: > key, val = i.split(":") > d[key] = val.strip() > > print d > print d["ip address"] > > > Getting below error : > key, val = i.split(":") > ValueError: need more than 1 value to unpack > -- > https://mail.python.org/mailman/listinfo/python-list If you iterate over a string, you are iterating over individual characters. Instead, you need to split it into lines, first stripping whitespace (starts and ends with an empty line). s = s.strip().replace("=",":") print s d = {} for i in s.split('\n'): try: key, val = i.split(":") d[key.strip()] = val.strip() except ValueError: print "no key:value pair found in", i (PS. please switch to Python 3) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Where has the practice of sending screen shots as source code come from?
On 28 January 2018 at 20:19, Chris Angelico wrote: > The vanilla Windows console (conhost.exe IIRC) is far from ideal for > copying and pasting from It’s been fixed in recent Windows 10 releases (select and Ctrl+C works now). > Windows error popups are *impossible* to copy text from. Most standard error popups support pressing Ctrl+C to copy the text displayed in them. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Repairing Python installation?
On 29 October 2017 at 18:11, Martin Schöön wrote: > I have installed Python 3 virtualenv and Nikola according to those > instructions. I now have a working Nikola but I sure don't know what > I am doing :-) How do I get back into that nikola python environment > next time? cd into your virtualenv directory and run `source bin/activate`. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Repairing Python installation?
On 28 October 2017 at 22:41, Martin Schöön wrote: > It seems something is amiss with my Python 2.7 installation. Revisiting > Nikola (static web site generator written in Python) for the first time > in several years the other day I experience some unexpected problems. I > got some help form the Nikola people and the conclusion is something > is broken with my Python 2.7. Pip list throws exceptions at me while > pip3 list works the way I expect it to do. > > All this is happening on a Debian machine. > > Questions: > > Should I try to pinpoint what is broken (and how is that done) or should > I just remove everything Python 2.7 and re-install? > > Could mixing pip installs with Debian distro installs of Python > packages lead to conflicts or other problems? Yes, it does, you should avoid that at all cost. The best way to do it is by using virtualenv. > Today I tried pip --version and got the following: > /usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py:1892: > UserWarning: /usr/lib/pymodules/python2.7/rpl-1.5.5.egg-info could not > be properly decoded in UTF-8 > warnings.warn(msg) That’s a warning, and it happens to be caused by the `rpl` apt package. Remove it from your system and try `pip --version` again: https://github.com/certbot/certbot/issues/3795 Now, onto fixing Nikola issues: As discussed on IRC, Nikola recommends (and will soon require) Python 3. And you’ll be better off with a virtualenv: install `virtualenv` from apt and follow the Getting started guide for Nikola: https://getnikola.com/getting-started.html If you still get unicode issues when compiling posts, make sure they’re saved as UTF-8, and that your locale is configured properly: https://chriswarrick.com/blog/2017/06/18/unix-locales-vs-unicode/ (Nikola’s co-maintainer over here.) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: choice of web-framework
On 23 October 2017 at 21:37, John Black wrote: > Chris, thanks for all this detailed information. I am confused though > with your database recommendation. You say you teach SQLAlchemy but > generally use PostgreSQL yourself. I can maybe guess why there seems to > be this contradiction. Perhaps PostgreSQL is better but too advanced for > the class you are teaching? Can you clarify on which you think is the > better choice? Thanks. Different Chris, but I’ll answer. Those are two very different things. PostgreSQL is a database server. It talks SQL to clients, stores data, retrieves it when asked. The usual stuff a database server does. Alternatives: SQLite, MySQL, MS SQL, Oracle DB, … SQLAlchemy is an ORM: an object-relational mapper, and also a database toolkit. SQLAlchemy can abstract multiple database servers/engines (PostgreSQL, SQLite, MySQL, etc.) and work with them from the same codebase. It can also hide SQL from you and instead give you Python classes. If you use an ORM like SQLAlchemy, you get database support without writing a single line of SQL on your own. But you still need a database engine — PostgreSQL can be one of them. But you can deploy the same code to different DB engines, and it will just work™ (assuming you didn’t use any DB-specific features). Alternatives: Django ORM. psycopg2 is an example of a PostgreSQL client library for Python. It implements the Python DB-API and lets you use it to talk to a PostgreSQL server. When using psycopg2, you’re responsible for writing your own SQL statements for the server to execute. In that approach, you’re stuck with PostgreSQL and psycopg2 unless you rewrite your code to be compatible with the other database/library. Alternatives (other DBs): sqlite3, mysqlclient. There are also other PostgreSQL libraries available. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: choice of web-framework
On 22 October 2017 at 13:48, Chris Angelico wrote: > On Sun, Oct 22, 2017 at 10:34 PM, Chris Warrick wrote: >> On 22 October 2017 at 13:25, Lele Gaifax wrote: >>> Chris Warrick writes: >>> >>>> Zope is effectively dead these days. >>> >>> Except it's alive and kicking: https://blog.gocept.com/ >>> >>> :-) >>> >>> ciao, lele. >> >> A few people still care, sure. But how alive is a project with 16 >> (sixteen) people on IRC (freenode #zope), 85 (eighty-five) stars on >> GitHub, and 205 issues on GitHub (since 2013)? >> > > I'm not too bothered by number of stars, nor necessarily by the issue > count (maybe a lot of their work is discussed by email, not the > tracker). Most important, to me, is the number of commits. And that > doesn't look too bad; there aren't a huge number of them, but they're > fairly consistently being made. So I'd say the project isn't dead, > though you could very well argue that it's merely playing catch-up. (I > didn't look at the content of the commits in detail or anything.) > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list Mailing lists are quiet as well: https://mail.zope.org/pipermail/zope/ https://mail.zope.org/pipermail/zope-dev/ For a web framework, the daily commit count is much less important than the size of the active community. An active community means more people that can offer support, fix bugs, write docs, provide ready-made modules to achieve common tasks. Zope’s community is nonexistent. Django has 1483 contributors and 29k stars on GitHub. Zope has 83 and 85 respectively. https://blog.gocept.com/2016/10/04/zope-resurrection-part-2-defibrillation/ > Zope is not dead. On the sprint there were nearly 20 people who use Zope for > their daily work. Oh my, twenty people! That’s a lot! A lot! Yeah, no. Zope is dead. With a few folks going through the “denial” phase. Or the “I’ve got legacy code from last decade I can’t be bothered to rewrite” phase. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: choice of web-framework
On 22 October 2017 at 13:25, Lele Gaifax wrote: > Chris Warrick writes: > >> Zope is effectively dead these days. > > Except it's alive and kicking: https://blog.gocept.com/ > > :-) > > ciao, lele. A few people still care, sure. But how alive is a project with 16 (sixteen) people on IRC (freenode #zope), 85 (eighty-five) stars on GitHub, and 205 issues on GitHub (since 2013)? -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: choice of web-framework
On 22 October 2017 at 12:24, Patrick Vrijlandt wrote: > Hello list, > > I would like your recommendation on the choice of a web framework. > > The project is completely new, there are no histories to take into account > (current solutions are paper-based). The website involves questionnaires > that will be developed, filled out and stored. Users are not programmers or > developers. They should be authenticated. Version control is required. > Internationalization is not an issue. I expect that the project will add > additional requirements and complexity later on that I can not foresee yet. > I'm targeting a single deployment (maybe a second on a development machine). > I usually work on Windows, but Linux can be considered. If you intend to put this on a server, and you probably do since you’re talking about web frameworks, a Linux machine is your best bet for that. Windows isn’t a good platform for making web servers out of. (Your development machine can probably run Windows.) > I'm not afraid to learn a (=one) new framework (that would actually be fun) > but trying out a lot of them is not feasible. My current goal is a > demonstration version of the project as a proof of concept. I may want to > hand it over to a commercial solution at that stage. > > I'm an experienced python programmer but not an experienced web developer. A > few years ago I read some books about Zope and Plone, but never did serious > development with those. I currently maintain an intranet site in MoinMoin. I > assume Zope could still be a potential choice, but it may have lost the > vibrancy of a few years ago. Also, I would not know which version to choose > (Zope 4, BlueBream, or something like Grok). The problem seems too > complicated for micro frameworks like bottle of Flask. Django could be the > next alternative. Zope is effectively dead these days. IMO your best bet would be Django: * built-in database support * built-in user authentication support * built-in administrator panel * i18n support available for when you need it * it’s a modern, friendly web framework If you went with Flask, you’d end up with a pile of plugins (for auth, for databases, for other things) and reimplement half of Django, badly. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Line terminators in Python?
On 29 September 2017 at 19:54, Stefan Ram wrote: > In some languages, printing »'\n'«, the Unicode code point 10, > will have the effect of printing a line terminator, which might > mean that the output device actually receives »\r\n«. > > The line terminator ostensibly depends on the operating > system, but actually it depends on the output system. E.g., > under one operating system the console might accept another > set of line separators than an editor. (Under Windows, > »wordpad« accepts »\n«, while »notepad« requires »\r\n«.) > > What is the recommended way to terminate a line written with > Python? Is it »\n« or something else? For example, in Java, > in some cases, one should terminate the line with the value > of »java.lang.System.lineSeparator()« which might or might > not be equal to the value of »"\n"«. > > Does it possibly depend on the entity being written to, which > might be > > - the Python console, > - the IDLE console, > - the operating system console or > - a text file? It depends on the mode used to open the output file. https://docs.python.org/3/library/functions.html#open sys.stdout is opened in 'w' mode by default (writing, text mode). Text mode means that non-Unix newlines (\r\n, \r) are translated to '\n' when reading, and '\n' is translated to the system local newline when writing. So, if you’re working in text mode (which also handles encodings and returns Unicode strings on Python 3), you can just assume '\n'. If you’re curious what the local newline is, look at os.linesep: https://docs.python.org/3/library/os.html#os.linesep -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Boolean Logic
On 23 September 2017 at 06:46, Cai Gengyang wrote: > Output : > > ('bool_one = ', False) > ('bool_two = ', False) > ('bool_three = ', False) > ('bool_four = ', True) > ('bool_five = ', False) You’re using Python 2 with Python 3-style print statements. To make it look good, start your code with: from __future__ import print_function Or use the Python 2 form (without parentheses), or even better: switch to Python 3. Now, Codecademy is a peculiar place. They still teach Python 2 (that sucks!) and have a specific teaching style. The way you’re supposed to solve this is to just assign your answers to bool_one through bool_five. You should just type True or False in each blank, using Python to evaluate this expression is kinda cheating. Codecademy will then tell you if you got the right answer. Don’t print stuff you aren’t asked to print. However, you should not depend only on Codecademy’s interpreter. Install Python on your computer and work with that. I also recommend learning using different resources, and learning Python 3. It’s the future. ~~~ On 23 September 2017 at 07:01, Bill wrote: > Your answers appear correct, but you could write Python statements to test > them (or any you encounter in the future). For instance, > > if (20 - 10) > 15 : > print("true") > else: > print("false"); > > Or, > > s='(20 - 10) > 15' > b=(20 - 10) > 15 > print(s, " is ", ("true" if b else "false") ); ## inside parentheses may be > removed. This outputs "False is false", because you used the variable in your expression. You can just do this: >>> print("s is", s) This will print "s is False". You can also replace your earlier `if` with: >>> print((20 - 10) > 15) (False will appear upper-case, of course.) PS. don’t use semicolons with Python. Avoid eval() as well. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Stdlib, what's in, what's out
On 20 September 2017 at 17:16, Dennis Lee Bieber wrote: > On Tue, 19 Sep 2017 11:58:47 -0700 (PDT), John Ladasky > declaimed the following: > >> >>And of course I have found some other third-party packages: scipy, pandas, >>matplotlib, and PyQt5 are important for my work. I helped a student of mine >>get selenium running. In the case of PyQt, I found TKinter unsatisfactory >>many years ago, and went looking for better choices. I used wxPython first, >>when I was working in Py2. When wxPython was slow to migrate to Py3, I went >>searching again. >> > > And if wxPython had been part of the stdlib, it would have meant > Python > 3 would have been delayed years until wxPython had been ported -- or > wxPython would have been pulled from the stdlib and something else put in > its place... > > So no help to those migrating. If wxPython had been part of the stdlib, there would be much more manpower to port it to 3. Also, the project underwent a complete rewrite, which dooms many projects to failure. Perhaps they wouldn’t try the rewrite, or they would port the older codebase to Python 3 so that it could be shipped. (They’re currently at Beta 2 of the post-rewrite 4.0.0 version.) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python dress
On 12 September 2017 at 21:15, Stephan Houben wrote: > Op 2017-09-12, Jona Azizaj schreef : >> It looks very nice, thanks for sharing :) > >print(insertionSort) > > It's even Python3-compliant! > > Stephan > -- > https://mail.python.org/mailman/listinfo/python-list Meh. That should be a return statement, the thing is not PEP 8-compliant, and Courier is an ugly font. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: People choosing Python 3
On 10 September 2017 at 11:24, Leam Hall wrote: > On 09/10/2017 04:19 AM, Chris Warrick wrote: >> >> On 10 September 2017 at 09:30, Marko Rauhamaa wrote: >>> >>> INADA Naoki : >>> >>>> I can't wait Python 3 is the default Python of Red Hat, and "python" >>>> command means Python 3 on Debian and Ubuntu. >>> >>> >>> I can't wait till Python 3 is available on Red Hat. >> >> >> Python 3.4 is available in EPEL. RHEL 8 will switch to Python 3 as the >> main Python interpreter (assuming dnf replaces yum, as it did in >> Fedora a while back). >> > > I'm not sure that RHEL 8 will be Python 3 for the OS tools. Even if it is, > which version? RHEL’s release process starts at forking a recent Fedora release. It wouldn’t make much sense for them to undo the Python 3 progress that happened over the past few years in Fedora — including dnf, an improved package manager written in Python 3. If the fork happened today, the base release would be Fedora 26, which includes Python 3.6, and some install options don’t include Python 2. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: People choosing Python 3
On 10 September 2017 at 09:30, Marko Rauhamaa wrote: > INADA Naoki : > >> I can't wait Python 3 is the default Python of Red Hat, and "python" >> command means Python 3 on Debian and Ubuntu. > > I can't wait till Python 3 is available on Red Hat. Python 3.4 is available in EPEL. RHEL 8 will switch to Python 3 as the main Python interpreter (assuming dnf replaces yum, as it did in Fedora a while back). -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: OT: Rejecting whitespace-only changes at github
On 10 August 2017 at 10:47, Hartmut Goebel wrote: > Hello, > > Is there some tool or online-service which can check patches if they > contain white-space-only changes and all test-wrapping changes? > > One of the projects I'm maintaining (pyinstaller) wants to forbid > changes of theses types. If we could integrate resp. checks into the > tooling (github), this would give contributors feedback quickly and ease > the burden for the maintainers. > > Sorry for this off-topic question, but I assume to find a competent > answer here. And thanks for any pointer. First, make sure you have a clear policy regarding code style. Set up an editorconfig file, mention it in CONTRIBUTING.rst or other developer documentation. There are some tools that enforce code style — eg. Codacy — but that might not be what you want. You can write a tool that interacts with GitHub in this way by writing a webhook: https://developer.github.com/webhooks/ You will need your own server (even the cheapest VPS will do) and some simple code in your favorite Python web framework (Flask). Get a webhook request whenever PRs are opened/changed, check if the PR is “clean” (download diff from GitHub, find whitespace-only changes?) and use the GitHub API to close PRs/comment on them/set status checks to “failed”. (Closing those PRs might be seen as harsh and discouraging to new contributors) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Are these tutorials the best tutorials for learning Python?
On 9 August 2017 at 17:14, Steve D'Aprano wrote: > On Wed, 9 Aug 2017 07:12 pm, Chris Warrick wrote: > >> So, I started by writing my opinion of those recommendations, and that >> the “community” is very small (<1k Twitter followers, 2.7k Facebook >> likes). But then I went to the “About Us” page, and found your name >> and your profile picture there. Native advertising is evil and rude. >> You made it sound as if you were an user, genuinely looking for help >> in learning Python. But in reality, you just want people to visit your >> website, get ad revenue and potentially get people to join your >> community. >> >> Shame on you. > > Why is this shameful? Why shouldn't people make money from their Python > expertise, if they can? Do you oppose people who get paid to program in > Python? > > If you're opposed to advertising, use an ad blocker, or just avoid the site. > > So long as the website isn't *exploitative* (ripping off other people's > content > without providing any added value) there is nothing wrong with promoting it > here. It is on-topic, and if it provides some added value (not just a link > farm), doesn't serve malware, then let it compete for eyeballs and hearts and > minds on its merits. I’m not opposed to advertising on websites[0], or to paying for expertise. I am opposed to the way the original post was phrased — it was a textbook case of native advertising. Wikipedia says: “Native advertising is a type of advertising, mostly online, that matches the form and function of the platform upon which it appears.” (from https://en.wikipedia.org/wiki/Native_advertising ) The original poster sent a message that looked like a genuine call for help by someone looking to learn Python. They somehow found the list[1] and want our opinion on it. But that wasn’t the posters real motive: the motive was to get people to use their website. And this is not okay. Compare the second revision (with [Repost] in the Subject line) — that one has clear information regarding the poster and their intentions, and it’s perfectly fine in my book. The damage was already done nevertheless. [0] As long as said advertising is not user-hostile. [1] It appears as the 10th hit in Google for “python tutorials” over here. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Are these tutorials the best tutorials for learning Python?
On 9 August 2017 at 10:29, Saurabh Hooda wrote: > Hello, > [advertisement] proclaims that it's a collection of the best tutorials > recommended by the programming community. Do you agree? Is there any better > tutorial? > > Thanks in advance, > Saurabh Hooda > -- > https://mail.python.org/mailman/listinfo/python-list So, I started by writing my opinion of those recommendations, and that the “community” is very small (<1k Twitter followers, 2.7k Facebook likes). But then I went to the “About Us” page, and found your name and your profile picture there. Native advertising is evil and rude. You made it sound as if you were an user, genuinely looking for help in learning Python. But in reality, you just want people to visit your website, get ad revenue and potentially get people to join your community. Shame on you. --- Your top recommendation is the worst Python tutorial in existence. Learn Python The Hard Way is not worth the $30 price tag. It’s discouragingly slow and boring. 19% of the book is printing. It makes you memorize truth tables instead of understanding logic. It often makes you Google things instead of teaching them. The author published an article full of FUD against Python 3 (explained: https://eev.ee/blog/2016/11/23/a-rebuttal-for-python-3/ )… and released a beta version of his Python 3 book shortly afterwards. You also have a lot of Python 2 content on the site. Content that teaches a legacy language. My recommendations: * Think Python, 2nd edition: http://greenteapress.com/wp/think-python-2e/ * Automate the Boring Stuff with Python: https://automatetheboringstuff.com/ * official Python tutorial, if you can already program, or to complement the other two: https://docs.python.org/3/tutorial/index.html All three are free to read online. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Connecting Google News
On 16 July 2017 at 11:26, Javier Bezos wrote: > Google News used to fail with the high level functions provided by httplib > and the like. However, I found this piece of code somewhere: > > def gopen(): > http = httplib.HTTPSConnection('news.google.com') > http.request("GET","/news?ned=es_MX" , > headers = >{"User-Agent":"Mozilla/5.0 (X11; U; Linux i686; es-MX) > AppleWebKit/532.8 (KHTML, like Gecko) Chrome/4.0.277.0 Safari/532.8", >"Host":'news.google.com', >"Accept": "*/*"}) > return http.getresponse() > > A few days ago, Google News has been revamped and it doesn't work any more > (2.6/Win7, 2.7/OSX and, with minimal changes, 3.6/Win7), because the page > contents is empty. The code itself doesn't raise any errors. Which is the > proper way to do it now? I must stick to the standard libraries. Why? The Python standard library doesn’t have anything good for HTTP. * httplib is fairly low-level, and it does not support something as basic as redirects; * urllib.request (urllib2 in Python 2) is slightly better; * but even the official docs for both redirect to requests: http://docs.python-requests.org/en/master/ for a high level interface. (Also, please upgrade your Windows box to run Python 2.7.) > The returned headers are: > > -- > [('Content-Type', 'application/binary'), > ('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate'), > ('Pragma', 'no-cache'), > ('Expires', 'Mon, 01 Jan 1990 00:00:00 GMT'), > ('Date', 'Thu, 13 Jul 2017 16:37:48 GMT'), > ('Location', 'https://news.google.com/news/?ned=es_mx&hl=es'), > ('Strict-Transport-Security', 'max-age=10886400'), > ('P3P', > 'CP="This is not a P3P policy! See ' > 'https://support.google.com/accounts/answer/151657?hl=en for more > info."'), > ('Server', 'ESF'), > ('Content-Length', '0'), > ('X-XSS-Protection', '1; mode=block'), > ('X-Frame-Options', 'SAMEORIGIN'), > ('X-Content-Type-Options', 'nosniff'), > ('Set-Cookie', > 'NID=107=qwH7N2hB12zVGfFzrAC2CZZNhrnNAVLEmTvDvuSzzw6mSlta9D2RDZVP9t5gEcq_WJjZQjDSWklJ7LElSnAZnHsiF4CXOwvGDs2tjrXfP41LE-6LafdA86GO3sWYnfWs;Domain=.google.com;Path=/;Expires=Fri, > ' > '12-Jan-2018 16:37:48 GMT;HttpOnly'), > ('Alt-Svc', 'quic=":443"; ma=2592000; v="39,38,37,36,35"')] > --- > > `read()` is empty string ('' or b''). `status` is 302. `reason` is `Found`. https://en.wikipedia.org/wiki/HTTP_302 See that Location header? The web server wants to redirect you somewhere. Your low-level HTTP library does not handle redirects automatically, so you’d need to take care of that yourself. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Compiling Python 3.6.1 on macOS 10.12.5
Why are you trying to compile Python manually? You should use Homebrew to install Python in 99% of cases. (The package is python3) -- Chris Warrick <https://chriswarrick.com/> -- https://mail.python.org/mailman/listinfo/python-list
Re: Privy: An easy, fast lib to password-protect your data
On 5 July 2017 at 02:39, wrote: > On Monday, July 3, 2017 at 10:36:39 PM UTC-4, ofekm...@gmail.com wrote: >> https://github.com/ofek/privy > > Bump b/c spam > -- > https://mail.python.org/mailman/listinfo/python-list The person spamming right now would be you. You just posted a link, without any explanations, any marketing blurbs, nothing. Why would I use your tool instead of something established, that has been properly audited — say, PGP for example? How do I know your one-man project has no security holes, backdoors, or other vulnerabilities? How do I know that the encryption method chosen by you is sound? If there is no leaked data? And I really dislike the description of your project: > Privy is a small and fast utility for password-protecting secret data such as > API keys, cryptocurrency wallets, or seeds for digital signatures. What does “password-protecting” mean? Why is this not “encrypting”? How do you expect this to work with API keys? -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: how to convert json to csv with python?
On 3 June 2017 at 13:00, Ho Yeung Lee wrote: > i use > https://github.com/evidens/json2csv > > Error: > Traceback (most recent call last): > File "json2csv.py", line 148, in > loader.load(args.json_file) > File "json2csv.py", line 53, in load > self.process_each(json.load(json_file)) > File "C:\Python27\lib\json\__init__.py", line 291, in load > **kw) > File "C:\Python27\lib\json\__init__.py", line 339, in loads > return _default_decoder.decode(s) > File "C:\Python27\lib\json\decoder.py", line 367, in decode > raise ValueError(errmsg("Extra data", s, end, len(s))) > ValueError: Extra data: line 10 column 2 - line 50 column 2 (char 224 - 1179) > > sample file is > { > "ip": "184.85.123.122", > "hostname": "No Hostname", > "city": "Cambridge", > "region": "Massachusetts", > "country": "US", > "loc": "42.3626,-71.0843", > "org": "AS20940 Akamai International B.V.", > "postal": "02142" > }, > { > "ip": "203.185.0.32", > "hostname": "20318532.ctinets.com", > "city": "Central District", > "region": "", > "country": "HK", > "loc": "22.2910,114.1500", > "org": "AS9269 HKBN AS10103" > }, > [snip] This is invalid JSON. You need to wrap all your dicts in a JSON array, like this: [ { "ip": "…" }, { "ip": "…" } ] (just add [ and ] to the start and end of your file) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python package to accept payments in Internet
On 3 May 2017 at 17:58, Victor Porton wrote: > Chris Warrick wrote: > >> On 3 May 2017 at 17:19, Victor Porton wrote: >>> What do you mean by "banned"? Does this mean that Google does not use >>> software of this license? >> >> https://opensource.google.com/docs/using/agpl-policy/ >> https://www.theregister.co.uk/2011/03/31/google_on_open_source_licenses/ > > It is irrelevant for me that Google Code bans my license (by the way it > seems that Google banned it only in the past, not now). I anyway host it at > GitHub not at Google Code. Google Code is dead, but the first link comes from a guide published very recently: https://developers.googleblog.com/2017/03/a-new-home-for-google-open-source.html You might argue that Google’s opinion is irrelevant to you — and you would be right, since Google isn’t using Django, and has their own payments platform. But there might be other users that will avoid your package for licensing reasons. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python package to accept payments in Internet
On 3 May 2017 at 17:19, Victor Porton wrote: > What do you mean by "banned"? Does this mean that Google does not use > software of this license? https://opensource.google.com/docs/using/agpl-policy/ https://www.theregister.co.uk/2011/03/31/google_on_open_source_licenses/ > My package is a professional tool unlike other's hacks. You yourself called your code a hack: >> Also, this line looks unconvincing: >> >> # This is a quick hack. For serious work use >> https://github.com/paypal/PayPal-Python-SDK instead. > > This quick hack does work for the purpose it was made. This class is > not feature-rich, but other features are not needed by other parts of > my software. So it's OK. No, it’s not okay. Quick hacks are never good when dealing with money. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python package to accept payments in Internet
On 3 May 2017 at 16:45, Victor Porton wrote: > Steve D'Aprano wrote: > >> On Wed, 3 May 2017 02:19 am, Victor Porton wrote: >> >>> I have created a full featured package to accept payments in Internet >>> (currently supports PayPal). >> [...] >>> Buy the commercial version and support scientific research and a new >>> principle of the Web I am working on. >> >> What licence is your package? Is it under an open source licence, or >> commercial closed source, or is there a choice? > > It is licensed both AGPLv3+ (an open source license) and a commercial > license. > > The AGPL license requires you to publish your Web application source code if > my package is called from your software. > > Thus you may need the commercial license for your closed source Web > application (that is for your site). > > See > > http://freesoft.portonvictor.org/django-debits.xml > > for more information. The AGPL license is banned by Google, and perhaps many others. There are other packages for handling payments, many with a saner license and available for free, so you’ll be pretty unsuccessful. Also, this line looks unconvincing: # This is a quick hack. For serious work use https://github.com/paypal/PayPal-Python-SDK instead. source: https://github.com/vporton/django-debits/blob/fe8681042dbbf0353d1a29299280326a059452ca/debits/paypal/models.py#L9 Your website is ugly, uses default browser styles, and to me it feels like you don’t pay attention to important stuff. That’s not someone who I’d trust to do payments right. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Calling dunder methods manually
On 13 April 2017 at 09:43, eryk sun wrote: > The functions in the operator module implement abstract behavior (e.g. > PyNumber_Add in CPython): > > >>> operator.__add__(C(), D()) > 42 Those functions also do not need underscores — operator.add is a prettier way to achieve the same result. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: SimpleHTTPServer and CgiHTTPServer in practice
On 17 March 2017 at 01:28, Paul Rubin wrote: > Lutz Horn writes: >> We don't know *why* those people told you not to use these modules. We >> also don't know your use case. So it is very hard to advise you. > > The use case is to have a very easily set up way to serve basic pages > and files, without a lot of configuration files and other > infrastructure. The main reason not to use it would be security holes > if there are some. I haven't examined the code carefully but didn't see > obvious issues at a quick glanace. I frankly worry more about large C > programs than Python programs. > -- > https://mail.python.org/mailman/listinfo/python-list Security isn’t the main problem. SimpleHTTPServer is fine for small, local, one-off servers. However, for anything large, there are two problems: (a) its ephemeral nature, and (b) slow performance (no caching). nginx (or apache if you must) takes only a few minutes to set up, and does not have those problems. CgiHTTPServer? It’s 2017 and CGI should be long dead. CGI means firing up a Python/Perl/$cgi_language interpreter on every single HTTP request, already a waste of time. And then, CGI scripts take input via random environment variables (not very dependable) and output to stdout, which is a completely broken architecture. Give up and run a real web framework (Django) using uWSGI and nginx. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Odd wording it docs for shutil.move?
On 3 March 2017 at 18:13, Grant Edwards wrote: > At https://docs.python.org/2/library/shutil.html it says: > > shutil.move(src, dst) > > Recursively move a file or directory (src) to another location > (dst). > > [...] > > If the destination is on the current filesystem, then os.rename() > is used. Otherwise, src is copied (using shutil.copy2()) to dst > and then removed. > > What does the current filesystem have to do with anything? > > Surely, what matters is whether and are on the same > filesystem? For the same reason it matters for /bin/mv. If the source and target are on the same filesystem, the files are just renamed, which is usually instantaneous (only file metadata needs to be changed). But if they are on different filesystems, “move” really means “copy and delete original”, which takes much longer. From macOS/BSD manpages, mv(1): As the rename(2) call does not work across file systems, mv uses cp(1) and rm(1) to accomplish the move. See also: https://en.wikipedia.org/wiki/Mv -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python application launcher (for Python code)
On 21 February 2017 at 20:21, Grant Edwards wrote: > On 2017-02-21, Rob Gaddi wrote: >> On 02/20/2017 06:16 PM, Deborah Swanson wrote: >> >> > [snip lots about using Windows but rather be >> > using Linux but not wanting to have to spend lots of >> > energy switching right now] >> >> You know, I'm always reluctant to recommend it, because it can >> definitely get you tied in knots. But you're about the ideal candidate >> for looking into https://www.cygwin.com/ > > There are other ways to get "shell and unix-utilities" for Windows > that are less "drastic" than Cygwin: they don't try to provide a > complete a Unix development environment or the illusion of Unix > filesystem semantics. [Remember: a Unix shell without a set of > accompanying utilitys is pretty useless, since Unix shells don't have > all of the "built-in" commands that Windows shells do.] > > NB: I haven't used any of these lately... > > http://unxutils.sourceforge.net/ > http://www.mingw.org/ (look for msys) > https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058 (git's > bash-terminal) > https://sourceforge.net/projects/ezwinports/ > > There were a couple another very highly recommended commercial Unix > shell+utilities products (MKS Toolkit, Interix) that I used to > use. But AFAIK, they all got bought and killed by Microsoft. Git Bash, or basically msys, is pretty reasonable. But if you are on Windows 10, you might like the built-in Windows Subsystem for Linux (aka Bash on Ubuntu on Windows) more — it’s real Linux that runs alongside Windows, but less crazy than Cygwin. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Is requests[security] required for python 3.5+ ?
On 2 February 2017 at 20:41, Thomas Nyberg wrote: > Hello, > > I'm trying to understand whether requests[security] or just plain requests > should be installed for python 3.5. I.e. do the following packages need to > be installed: pyOpenSSL, cryptography,idna. > > The reason I'm asking is because I'm moving an application to python 3 and I > am testing out which requirements continue to be required in the version. No, requests[security] is only needed for old Python 2.7 versions (before 2.7.9). -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Let ipython3 use the latest python3
On 21 January 2017 at 12:30, Cecil Westerhof wrote: > I built python3.6, but ipython3 is still using the old one (3.4.5). > How can I make ipython3 use 3.6? All packages you have installed are tied to a specific Python version. If you want to use IPython with Python 3.6, you need to install it for that version (most likely, with pip) and make sure there is an ipython3 executable in your $PATH pointing at 3.6. You don’t need to remove IPython for 3.4 (but you can if you want to get rid of it). -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: print() with no newline
On 18 December 2016 at 13:25, ElChino wrote: > In this snippet: > import sys > PY3 = (sys.version_info[0] >= 3) > > def print_no_nl (s): > if PY3: > print (s, end="") > else: > print (s), > > I'm getting a syntax error in Python2. Python3 is fine. > How can I make this Py2+3 compatible? With a __future__ import, the Python 3 syntax will work with both Pythons: from __future__ import print_function print(s, end="") -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: The Case Against Python 3
On 25 November 2016 at 12:11, Fabien wrote: > I'd be interested to read what the community thinks about the fact that his > book (learn the hard way) is extremely influential among beginners, and what > tools do we have to avoid that beginners stumble across such opinions in > their very first steps with python... His book is slowly on the way out. #python on freenode and /r/python stopped recommending the book. Other places should follow suit, and actively discourage an outdated (easy_install, distribute, nosetests, python 2) book written by an asshole and a xenophobe. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: advanced SimpleHTTPServer?
On 2 November 2016 at 17:56, Eric S. Johansson wrote: >> Instead, you should use a real web server, such as nginx or apache. >> Those will do the first two properly, and the last one could be >> handled by a simple-ish PHP script. Or a full-fledged app in Django or >> Flask if you feel like it. > or bottle. why does everyone seem to forget bottle? simple to set up, > easy to learn and useful for small to medium projects. The other frameworks are simple to set up, too. I’ve personally had Unicode issues with Bottle, and it doesn’t even do sessions. Unlike Flask, or of course Django. Because, as the old saying goes, any sufficiently complicated Bottle or Flask app contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Django. (In the form of various plugins to do databases, accounts, admin panels etc.) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: advanced SimpleHTTPServer?
On 2 November 2016 at 08:27, Ulli Horlacher wrote: > "python -m SimpleHTTPServer" is really cool :-) > > But I need some more features: > > - some kind of a chroot, to prevent file access higher then the base > directory > > - a directory listing mit date and size information > > - an upload possibility > > I could modify /usr/lib/python2.7/SimpleHTTPServer.py by myself, but maybe > someone already has implemented these features? > > Use case: users with notebooks in a foreign (WiFi) LAN want to exchange > some files on-the-fly, quick-and-dirty. Using USB sticks is a no-go! :-) SimpleHTTPServer is meant to be used for development and testing. It should not be used for anything remotely serious for security and speed reasons. Instead, you should use a real web server, such as nginx or apache. Those will do the first two properly, and the last one could be handled by a simple-ish PHP script. Or a full-fledged app in Django or Flask if you feel like it. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: New to python
On 17 October 2016 at 21:51, Bill Cunningham wrote: > I just installed python I might start with 3. But there is version 2 out > too. So far I can '3+4' and get the answer. Nice. I typed the linux man page > and got a little info. So to learn this language is there an online > tutorial? I am interested in the scripting too. > > Bill Learn Python 3. Good resources (that I can actually vouch for being good…) include: https://docs.python.org/3/tutorial/index.html (if you can already program) http://greenteapress.com/wp/think-python/ https://automatetheboringstuff.com/ -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: TCL/TK as default UI toolkit, and wayland
On 14 October 2016 at 13:40, kerbingamer376 wrote: > Python's "standard" (and bundled on most platforms) UI tookkit is TCL/TK. > However, this has A LOT of drawbacks: > > * It's eyesore on a lot of platforms > * It's non-pythonic > * It just flat out fails on some desktop environments > * On linux it requires X, however lots of distros are now using wayland > and so on. > > I think python needs a new "standard" UI toolkit. > -- > https://mail.python.org/mailman/listinfo/python-list Okay. What else do you suggest? * PyQt/PySide requires massive Qt packages, and has licensing issues. * GTK looks bad outside of GNOME. * wxPython claims to be back to development, but it wasn’t for the past 2 years. * Kivy doesn’t even try to feel native anywhere. I think we’ve just run out of reasonable cross-platform GUI libraries for Python… You are free to use any of those four, though (or anything less cross-platform). You don’t have to use Tkinter if you don’t like it. And it’s not a hard requirement on many Linux distributions. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Structure of program development
On 4 July 2016 at 18:07, Michael Smolen <8smo...@tds.net> wrote: > Folks: > > I am new to this programming adventure. I've gotten past the introductory > chapters in 'How to..." books and now want to start developing a much more > complicated program that I will use repeated for different applications. When > I worked in Perl there was an option to write a program in a text editor, > save it, and then run in with Perl. Is such a thing possible in Python? If > not, how do I develop a 500+ lines of code? Yes, the same way it works in Perl. Use the .py file extension and run the `python` interpreter from command line, or use an IDE that would help you with that. > A second question of the basic design. If I write a program, can I move it to > a computer that is without any Python software, or does that machine have to > download the Python software? Does Python products contain all parts of a > developed program or is it a series of 'call' statements? You must either install a Python interpreter on that machine, or distribute one with your program. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating a calculator
On 1 July 2016 at 11:34, Pierre-Alain Dorange wrote: > DFS wrote: > >> Here's a related program that doesn't require you to tell it what type >> of operation to perform. Just enter 'num1 operator num2' and hit Enter, >> and it will parse the entry and do the math. >> >> --- >> ui=raw_input('Enter calculation to perform: ') >> n1=float(ui.split(' ')[0]) >> op=ui.split(' ')[1] >> n2=float(ui.split(' ')[2]) >> if op=='+':c=n1+n2 >> if op=='-':c=n1-n2 >> if op=='*':c=n1*n2 >> if op=='/':c=n1/n2 >> print(ui+' = '+str(c)) >> --- > > More reduced : > -- > u=raw_input('Enter calculation:") > print eval(u) > -- > works and compute : > 1+2+3+4-1+4*2 > 2+3.0/2-0.5 > > Perform better and shorter, but less educationnal of course... No, this is awful. It’s a great way to compromise your system’s security. Never use eval() for any reason, especially with user input — if you were to type in __import__('os').system('…') with some particularly dangerous command (rm, format, …), you would kill your system. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating a calculator
On 1 July 2016 at 05:08, Elizabeth Weiss wrote: > while True: > print("Options:") > print("Enter 'add' to add two numbers") > print("Enter 'subtract' to subtract two numbers") > print("Enter 'multiply' to multiply two numbers") > print("Enter 'divide' to divide two numbers") > print("Enter 'quit' to end the program") > user_input=input(":") > if user_input=="quit": > break > elif user_input=="add": > num1=float(input("Enter a number")) > num2=float(input("Enter another number")) > result=str(num1+num2) > print("The answer is"+ result) > elif user_input=="subtract": > num1=float(input("Enter a number")) > num2=float(input("Enter another number")) > result=str(num1-num2) > print("The answer is"+result) > > Two questions: > 1. Why do I need to put ' ' around the words add, subtract, multiply, quit, > etc. when it is already in quotes in print()? When the calculator asks me > which option I would like to choose I do not write 'add'- I only write add. This is used for display. The single quotes will be displayed as part of the string. This is so that people notice the commands, for example. >>> print("Enter 'add' to add two numbers") Enter 'add' to add two numbers >>> print("Enter add to add two numbers") Enter add to add two numbers >>> print('Enter "add" to add two numbers') Enter "add" to add two numbers > 2. The program I am using to help me learn python mentions that the output > line could be put outside the if statements to omit repetition of code. What > does this mean and how would I write the code differently according to this? Look at your current code. The following three lines appear twice (and will appear 4 times if you add multiplication and division): > num1=float(input("Enter a number")) > num2=float(input("Enter another number")) > print("The answer is"+ result) This is code repetition. It’s discouraged, because if you have 4 copies of a longer segment, and you want to change something, you would have to remember to change it in 4 places. In this case, you can avoid code reuse like this: 1. Check if user said 'quit', and if yes, break from the loop. (Ignore invalid input for now) 2. Ask the user for two numbers. 3. Make an if/elif/else structure to calculate the result. 4. Print out the result outside of `if`. Example for 3. and 4.: if user_input == 'add': result = num1 + num2 # no need to call str() if you use commas in print() elif user_input == 'subtract': result = num1 - num2 # other elif clauses go here print("The result is", result) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: not able to install mysqldb-python
On 24 June 2016 at 09:46, Arshpreet Singh wrote: > On Thursday, 23 June 2016 23:18:27 UTC+5:30, Joaquin Alzola wrote: >> >ImportError: No module named 'ConfigParser' >> It is telling you the error >> This email is confidential and may be subject to privilege. If you are not >> the intended recipient, please do not copy or disclose its content but >> contact the sender immediately upon receipt. > > Thanks but somehow it fixed itself. :P now able to install mysql-python > without any problem. > -- > https://mail.python.org/mailman/listinfo/python-list It didn’t. mysql-python is installable with Python 2 only, so you probably installed it for your system Python 2 install instead of your Python 3 django virtualenv. Either way, please use mysqlclient instead, as recommended by the Django developers. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: pypi download links (e.g. for ansible)
On 9 May 2016 at 13:35, Michael Ströder wrote: > Steven D'Aprano wrote: >> On Mon, 9 May 2016 08:00 pm, Michael Strc3b6der wrote: >> >>> HI! >>> >>> Deep-links for downloading a specific version from PyPI seemed to work >>> like this: >>> >>> $ wget >>> https://pypi.python.org/packages/source/a/ansible/ansible-2.0.1.0.tar.gz >>> [..] >>> Saving to: ‘ansible-2.0.1.0.tar.gz’ >>> >>> But this recent version does not work: >>> >>> $ wget >>> https://pypi.python.org/packages/source/a/ansible/ansible-2.0.2.0.tar.gz >>> [..] >>> HTTP request sent, awaiting response... 404 Not Found >> >> >> Do you have a question, or are you just sharing? >> >> The Download button for 2.0.2.0 links to: >> >> https://pypi.python.org/packages/b3/0e/5f3ee8884866a3d5e3b8ba86e9caa85ecdec75adabac8924b1c122339e7f/ansible-2.0.2.0.tar.gz > > Yes, but in .spec files of openSUSE RPMs the more readable links above are > used > and I'd like to keep it that way. And openSUSE build service checks whether > it's > downloadable. It works for ansible-2.0.1.0 but not for 2.0.2.0. > > Ciao, Michael. > > -- > https://mail.python.org/mailman/listinfo/python-list PyPI URLs were changed recently. There is, however, a new supported way to get dependable URLs: https://bitbucket.org/pypa/pypi/issues/438/backwards-compatible-un-hashed-package The current link: https://files.pythonhosted.org/packages/source/a/ansible/ansible-2.0.1.0.tar.gz (URLs in the pypi.io domain were used briefly and will still work) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Advice on Python build tools
On 12 April 2016 at 11:48, Sayth Renshaw wrote: > Hi > > Looking at the wiki list of build tools > https://wiki.python.org/moin/ConfigurationAndBuildTools > > Has anyone much experience in build tools as i have no preference or > experience to lean on. > > Off descriptions only i would choose invoke. > > My requirements, simply i want to learn and build a simple static website > generator. Many i am not liking design of or are overkill so its a good > opportunity to learn, logya is a good starting point for what i think a good > python static generator should be. > > Second i want to use Jade templates (js) as i think they are more pythonic > than jinja and mako so being able to have mixed js and python support would > be needed. > > Thoughts? > > Sayth > -- > https://mail.python.org/mailman/listinfo/python-list Here’s a great static site generator (disclaimer, I’m a core dev over there): https://getnikola.com/ We use doit, which is on that list. With doit, we get an existing build system, and incremental rebuilds — for free. I recommend you try Nikola, and if you don’t like it and still want to build something yourself, doit is going to be a great way to do it. That said, incremental builds often involve trial-and-error and subtle bugs when you start working on it. And if you don’t like doit, you can always write your own build micro-system. Because if you want to write something simple and minimal, an existing large build system will just make things harder. As for Jade templates, you can’t do that reasonably. You would need to produce some hack to spawn a JavaScript subprocess, and it would limit what you can use in templates. Instead, look for a template system that is written in Python and that has similar syntax. (also, I wouldn’t consider such weird-thing-into-real-HTML template engines pythonic) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: How to make Python interpreter a little more strict?
On 25 March 2016 at 13:06, Aleksander Alekseev wrote: > Hello > > Recently I spend half an hour looking for a bug in code like this: > > eax@fujitsu:~/temp$ cat ./t.py > #!/usr/bin/env python3 > > for x in range(0,5): > if x % 2 == 0: > next > print(str(x)) > > eax@fujitsu:~/temp$ ./t.py > 0 > 1 > 2 > 3 > 4 > > Is it possible to make python complain in this case? Or maybe solve > such an issue somehow else? > > -- > Best regards, > Aleksander Alekseev > http://eax.me/ > -- > https://mail.python.org/mailman/listinfo/python-list You were probably looking for `continue`. This is just bad memory on your part, and Python can’t help. In the REPL, typing an object name is legal and helpful. Other languages might crash, sure — but they usually don’t have a REPL like Python does. That said, this code is designed badly. Here’s a better idea (also, note the fixed print statement): for x in range(0, 5): if x % 2 != 0: print(x) Or even with a more suitable range() that adds 2 instead of 1 in each step: for x in range(1, 5, 2): print(x) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python boilerplate
On 21 March 2016 at 00:36, Fernando Felix do Nascimento Junior wrote: > I made the boilerplate with intent that everyone can understand, download and > use quickly. So, I didn't put extra dependence like cookiecutter (that > depends jinja, that depends markupsafe) to **just** replace fields and then > run the project. I used “replace manually” before, and it was painful. > I also preferred to use .md instead .rst because it's more clean in my > opinion and used by default in platforms like GitHub and Stackoverflow. See > mkdocs to generate documentation with markdown. The vast majority of the Python community uses Sphinx and reST. In fact, that’s the only thing accepted on readthedocs.org, which is a popular documentation platform. > I didn't understand why packages are best than modules... both can be > reusable and not every project needs packages. It might not need it today, but it will probably grow. At which point you will notice that a module is not enough. You can also easily separate code with packages. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: WP-A: A New URL Shortener
On 15 March 2016 at 20:56, Vinicius Mesel wrote: > Hey guys, > > I'm a 16 year old Python Programmer that wanted to do something different. > But, like we know, ideas are quite difficult to find. > So I decided to develop a URL Shortener to help the Python community out and > share my coding knowledge, and today the project was launched with its first > stable version. > So if you want to see the software working, go check it out at: > http://wp-a.co/ > Or if you want to see the source code to contribute and help the project: > https://github.com/vmesel/WP-A.CO > > > Hugs, > Vinicius Mesel > Brazilian and Portuguese Speaker > http://www.vmesel.com > > > > -- > https://mail.python.org/mailman/listinfo/python-list This is a great exercise — however, your code is bad. You use string formatting to create SQL, which leads to SQL injection vulnerabilities. Please educate yourself on what those mean and how to avoid that in Python (hint: prepared statements). Also, you should not commit your sqlite database to git. That said, an URL shortener can be written in Django in less than an hour, and it will be even neater. (PS. the page’s really ugly. Consider using Bootstrap or some other existing framework if you’re not good at designing pretty things.) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: WP-A: A New URL Shortener
Please use reply-all in the future so that the list sees your message. On 17 March 2016 at 11:38, Vinicius wrote: > Thanks for replying Chris, > > Enviado do meu iPad > >> Em 16 de mar de 2016, às 1:18 PM, Chris Warrick >> escreveu: >> >>> On 15 March 2016 at 20:56, Vinicius Mesel wrote: >>> Hey guys, >>> >>> I'm a 16 year old Python Programmer that wanted to do something different. >>> But, like we know, ideas are quite difficult to find. >>> So I decided to develop a URL Shortener to help the Python community out >>> and share my coding knowledge, and today the project was launched with its >>> first stable version. >>> So if you want to see the software working, go check it out at: >>> http://wp-a.co/ >>> Or if you want to see the source code to contribute and help the project: >>> https://github.com/vmesel/WP-A.CO >>> >>> >>> Hugs, >>> Vinicius Mesel >>> Brazilian and Portuguese Speaker >>> http://www.vmesel.com >>> >>> >>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >> >> This is a great exercise — however, your code is bad. You use string >> formatting to create SQL, which leads to SQL injection >> vulnerabilities. Please educate yourself on what those mean and how to >> avoid that in Python (hint: prepared statements). Also, you should not >> commit your sqlite database to git. >> > Thanks for checking out my code and answering me, I will do the corrections > for the SQL Injection vulnerabilities with prepared statements like you said. > > The database in the git is to show to everyone how the URL is stored. You can show people a schema and write a small script that imports it. You may add some demo URLs if you insist. >> That said, an URL shortener can be written in Django in less than an >> hour, and it will be even neater. >> > > I did not make it in Django because I was in need to learn flask for other > projects. > > >> (PS. the page’s really ugly. Consider using Bootstrap or some other >> existing framework if you’re not good at designing pretty things.) > > I'll consider it. > >> -- >> Chris Warrick <https://chriswarrick.com/> >> PGP: 5EAAEA16 > > @vmesel -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python boilerplate
On 19 March 2016 at 13:43, Fernando Felix do Nascimento Junior wrote: > A simple boilerplate for those who don't know the structure of a project. > https://goo.gl/lJRvS6 > > ## Features > > * Build and distribute with setuptools > * Check code style with flake8 > * Make and run tests with pytest > * Run tests on every Python version with tox > * Code coverage with coverage.py > > [snip] > > Fernando Felix I would recommend using cookiecutter, a tool that automates things like these. I have my own template, based on cookiecutter: https://github.com/Kwpolska/python-project-template — it has a comprehensive `release` script, and follows best practices (including entry_points or packages instead of modules). It also uses .rst instead of .md documents. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Beginner Python Help
On 18 Mar 2016 08:05, "Alan Gabriel" wrote: > > Hey there, > > I just started out python and I was doing a activity where im trying to find the max and min of a list of numbers i inputted. > > This is my code.. > > num=input("Enter list of numbers") > list1=(num.split()) > > maxim= (max(list1)) > minim= (min(list1)) > > print(minim, maxim) > > > > So the problem is that when I enter numbers with an uneven amount of digits (e.g. I enter 400 20 36 85 100) I do not get 400 as the maximum nor 20 as the minimum. What have I done wrong in the code? You're dealing with strings (text) and not integers. And when comparing strings, '1' is earlier than '2', thus '100' < '20'. To fix this, you can use a list comprehension: list1 = [int(i) for i in num] You also don't need (parentheses) around functions when assigning to variables: maxim = max(list1) minim = min(list1) (Also, list1 is not a good variable name. Try something that describes its contents.) -- Chris Warrick <https://chriswarrick.com/> Sent from my Galaxy S3. -- https://mail.python.org/mailman/listinfo/python-list
Re: E-commerce system in Python
On 18 March 2016 at 05:25, Arshpreet Singh wrote: > I am looking for an E-commerce system in python to sell things things online, > which can also be responsive for Android and IOS. > > A quick Google search brought me http://getsaleor.com/ it uses Django, Is > there any available one using Flask or newly born asyncio based framework? > -- > https://mail.python.org/mailman/listinfo/python-list asyncio is, as you said, brand new — probably nothing exists. Why not use the existing Django solution though? What is your problem with it? It’s a great framework that does a lot of the hard work for you. Flask is low-level. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: pdf version of python tutorial
On 13 March 2016 at 14:45, kamaraju kusumanchi wrote: > Is there a pdf version of the python tutorial > https://docs.python.org/3/tutorial/index.html that I can download? The > idea is to have everything in one file so I can search easily, be able > to work offline. > > thanks > raju > -- > Kamaraju S Kusumanchi | http://raju.shoutwiki.com/wiki/Blog > -- > https://mail.python.org/mailman/listinfo/python-list There is a download link on the documentation index: https://docs.python.org/3/download.html -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Question
On 7 March 2016 at 19:09, Jon Ribbens wrote: > On 2016-03-07, Ian Kelly wrote: >> On Mon, Mar 7, 2016 at 9:39 AM, Ben Morales wrote: >>> I am trying to download Python but I have windows 10 and I do not see a 64 >>> bit download for my operating system. Do you have a 64 bit for windows? >> >> What page are you looking at? >> https://www.python.org/downloads/release/python-351/ has downloads for >> both Windows x86 and Windows x86-64. > > It only appears to have downloads for 32-bit, or 64-bit AMD processors, > not 64-bit Intel processors. > -- > https://mail.python.org/mailman/listinfo/python-list Modern Intel processors use the amd64 (aka x86_64) architecture. Intel’s Itanium architecture (IA-64) never really took off, and was not supported by the consumer versions of Windows (other than XP x64). (Not to mention 32-bit processors are sometimes called i386…i686, where the i stands for Intel, and those processors were also manufactured by AMD and others) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Everything good about Python except GUI IDE?
On 28 February 2016 at 15:11, Rustom Mody wrote: > On Sunday, February 28, 2016 at 7:30:57 PM UTC+5:30, Chris Warrick wrote: >> On 28 February 2016 at 14:49, Rustom Mody wrote: >> > On Sunday, February 28, 2016 at 6:54:40 PM UTC+5:30, Gordon Levi wrote: >> >> Rustom Mody wrote: >> >> >Glade generates XML (last I saw) >> >> >XML is text... kinda... but not quite >> >> >eg XML is sometimes/somewhere space sensitive, sometimes not >> >> >This can generate messy diffs >> >> >> >> That is also true of Python code but does not preclude effective >> >> source control. >> > >> > Yes as I said its not satisfactory but not impossible to manage >> > >> > Heck Current state of art VCSes cannot even manage mismatching EOL >> > conventions >> > cleanly. >> > And as usual they make a virtue out of the lack: >> > "git stores binary data not text" >> > >> > which means that opening a file created on windows on linux and saving it >> > in >> > WITHOUT a SINGLE CHANGE >> > can give you a 10,000 line diff!! >> > >> >> 2. A good editor can read and write any newline style. It should also >> not convert without asking the user. > > git is a *collaborative* tool and should work when the other party is using > notepad. What should git do if someone saves, say, Ruby code as a .py file? Should it rename it? Or should it figure out an equivalent snippet of Python? You probably have some rules in your project such as “Code must be written in Python” or “Use 4-space soft tabs”. Your rulebook should also include “Use an editor that understands LF line endings”. Notepad is a joke that you should not tolerate. Problem solved. (Notepad does not understand LF line endings and replaces them with boxes. I also don’t think a Notepad user is likely to provide good contributions, but that’s another thing) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Everything good about Python except GUI IDE?
On 28 February 2016 at 14:49, Rustom Mody wrote: > On Sunday, February 28, 2016 at 6:54:40 PM UTC+5:30, Gordon Levi wrote: >> Rustom Mody wrote: >> >Glade generates XML (last I saw) >> >XML is text... kinda... but not quite >> >eg XML is sometimes/somewhere space sensitive, sometimes not >> >This can generate messy diffs >> >> That is also true of Python code but does not preclude effective >> source control. > > Yes as I said its not satisfactory but not impossible to manage > > Heck Current state of art VCSes cannot even manage mismatching EOL conventions > cleanly. > And as usual they make a virtue out of the lack: > "git stores binary data not text" > > which means that opening a file created on windows on linux and saving it in > WITHOUT a SINGLE CHANGE > can give you a 10,000 line diff!! You clearly haven’t ever done that. 1. git can manage EOL changing if you want to enforce a newline style that way. 2. A good editor can read and write any newline style. It should also not convert without asking the user. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO
On 8 February 2016 at 16:53, Random832 wrote: > On Mon, Feb 8, 2016, at 10:46, Chris Angelico wrote: >> > I still think we should just retroactively declare 3.5 to be python 5, >> > and then keep going with python 6, 7, etc... >> >> http://dirtsimple.org/2004/12/python-is-not-java.html > > Java's hardly the only, or even the first, project to drop a version > number. (I think the first may actually have been GNU Emacs), and it's > certainly not the only one with a release schedule that frequently > increments the major version number. > -- > https://mail.python.org/mailman/listinfo/python-list In fact, this was done by a very popular Python project two years ago. That project is pip, which went from 1.5.6 to 6.0, and is now at 8.0.2. And its best friend setuptools is up to version 20.0. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: I can not install matplotlib, numpy, scipy, and pandas.
On 5 January 2016 at 07:57, Omar Ray via Python-list wrote: > I have version 3.5 of Python for Windows. I have MS Visual C++ and also MS > Visual Studio 2015. > > When I enter into the command window "pip install matplotlib", it reads this > below (this is not the full version of it): > > [snip] > > How do I download matplotlib and the other packages mentioned in the subject > line? > > > > -Omar Ray > > -- > https://mail.python.org/mailman/listinfo/python-list On Windows, using prebuilt binaries is recommended instead of building things yourself: 1. Installing matplotlib and pandas using pip, without mentioning scipy and numpy just yet. 2. Install scipy and numpy from http://www.lfd.uci.edu/~gohlke/pythonlibs/ (download matching files and run pip install c:\path\to\file.whl ). If anything in 1. fails, get a wheel package from the website mentioned in 2. Alternatively, try: https://www.scipy.org/install.html#individual-binary-and-source-packages -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: CGI
On 27 December 2015 at 18:59, Laurent Delacroix wrote: > On 26/12/15 10:41, Pol Hallen wrote: >> >> How can I execute a local command (like ls or similar) and show output >> via browser? >> > > Either you use a proper web framework (Flask, Bottle, Django in order of > complexity) or you set up a web server with FastCGI support (e.g. nginx) > and run a WSGI application behind it. > > Useful link: > https://docs.python.org/2/howto/webservers.html#setting-up-fastcgi > > Lau > -- > https://mail.python.org/mailman/listinfo/python-list Better yet, use a real WSGI server like uWSGI and its associated nginx module. (there are plenty of tutorials around the Internet) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python and multiple user access via super cool fancy website
On 25 December 2015 at 13:15, Aaron Christensen wrote: > LOL. Thanks! PHP was definitely not very easy to pick up and I'm still > having some issues. Last night I watched some tutorials on Django and plan > on reading all of the links on the docs page of Django. I will also look at > your recommendation. I think that will give me a good understanding. > Hopefully Django isn't a copy/paste kinda "put your website together" like > WordPress because my objective is to actually learn Python. That’s not what WordPress is. WordPress is a blog engine that can be used as a general-purpose CMS, full stop. You don’t need any coding skills to build a website with WordPress. Many people have done that — especially on wordpress.com or shared hosting services with one-click WP installers; and even without an installer, setting up WordPress on shared hosting requires a FTP client and reading comprehension anyways. On the other hand, Django is nothing like this. Django can do anything you tell it to, and you need to write code. While Django handles some things for you (eg. the admin panel or the ORM), you still need to write models, views, URL configuration, etc. yourself. You need an understanding of relational databases, HTTP, HTML/CSS, the template engine, and you do need to write actual code. And while there are tons of ready-made blog applications for Django that you can install and use, you can (and should!) write your own in an hour or two. And it’s a lot more fun to do that than lazily downloading something. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python and multiple user access via super cool fancy website
[Forwarding your message to the mailing list — please use the Reply All (or Reply to List) button in the future] On 25 December 2015 at 05:02, Aaron Christensen wrote: > Hi Chris, > > Thank you for your response and information. I enjoy doing Python on my > free time so when I get closer to some kind of web application, then I can > provide more information. > > Thanks for pointing me in the right direction so far. I will replace any > shelve usage with the database. I also started looking at WSGI servers and > just found a great deal of information on fullstackpython.com. Full Stack Python is a good resource, which teaches many things considered best practices in the Python web world (I personally recommend uWSGI instead of Gunicorn, but that’s mainly just my preference) > I have some experience in PHP (which is why I mentioned it). I am > unfamiliar with Django, Flask, or Pyramid. I am looking into Django, but am > a little hesitant because of all the time I spent learning PHP. I’m sorry, but you wasted your time. PHP is an awful language with multiple problems and bad design decisions. Here’s some laughing stock: http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ http://reddit.com/r/lolphp http://phpsadness.com/ On the other hand, Python web frameworks are really fun and easy to learn, even though their general design is a bit different from PHP’s: https://docs.djangoproject.com/en/1.9/intro/tutorial01/ http://tutorial.djangogirls.org/en/ -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python and multiple user access via super cool fancy website
On 24 December 2015 at 20:39, Aaron Christensen wrote: > Hi all, > > I am not sure if this is the correct venue for my question, but I'd like to > submit my question just in case. I am not a programmer but I do have an > incredible interest in it, so please excuse my lack of understanding if my > question isn't very thorough. > > As an example, a website backend is developed using Python. Users can > submit their input through the website and PHP (or some other language) Cut out the middle man! Write your web app in Python, which is much saner and more modern than PHP ever will be. Write it in Django, or Flask, or Pyramid, or [insert favorite web framework here]. > transfers the user input from the website fields to a database such as > MySQL. There is a main script called main_script.py which extracts the > user data from MySQL, processes it, stores output in MySQL and sends output > to the user (via webpage and email). > > About main_script.py > # main_script.py extracts user input from MySQL, processes it, stores > output in MySQL and send output to user (via webpage and email). > # Inputs: User personal information such as age, dob, nationality, hobbies, > and 20 or 30 other fields > # Output: main_script.py is going to do something with it such as access > the database and some shelve files or other py scripts. I have no clue what > it's going to do, but my point is that the processing of the input to > output will take longer than simply a print('Hello, %r!' %user_name). Well then, figure it out first.You shouldn’t be using shelve, it’s really unsafe and error-prone — and you already have a perfectly serviceable database! (PS. PostgreSQL is better) > My question: I am curious to know how Python handles something like this. > Let's say that there are 10, 20, 50, or even 1000 users accessing the > website. They all put in their 20 to 30 pieces of input and are waiting on > some fancy magic output. How exactly does that work? Can multiple users > access the same script? Does the Python programmer need to code in a > manner that supports this? Are requests to the script handled serially or > in parallel? We don’t know how you will structure your application. If you do the “fancy magic” in your web app, which you should if it won’t take more than, say, 5 seconds, this will be handled by your WSGI server (eg. uwsgi), which typically can spawn threads and processes for your web application. Otherwise, you might need to use an async framework or a task queue with multiple workers. It would be better to have some idea of the desired output, though. There are many Python-based web services out there, eg. YouTube, Instagram or DISQUS. And they work well under constant load. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to use python 3.5
On 23 December 2015 at 07:38, Ankit Deshmukh wrote: > Hi there, > > > > I am maters student in India, We don’t care (expect that you made a typo there). > I have installed python 3.5 in my windows 10 > 64bit machine. Everything works fine except package installing. When in use > “pip install numpy” is shows unable to find *‘vcvarsall.bat’* I don’t know > how to fix it. I tried several things nothing works. You clearly haven’t tried enough, as this question is answered by a simple Google search. You need to: (a) install Visual Studio 2015 and configure it; or (b) find a binary package, eg. here: http://www.lfd.uci.edu/~gohlke/pythonlibs/ A student who wants to work in programming should be able to find answers to their questions online. And know better than putting a phone number in their e-mail signature for the whole world to see. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Need help on a project To :"Create a class called BankAccount with the following parameters "
On 12 December 2015 at 11:29, Harbey Leke wrote: > oh oh okay start it for me please > thanks or guide me about it then. > -- > https://mail.python.org/mailman/listinfo/python-list class BankAccount(object): # your code goes here Seriously: read the materials you got with your course, or the Python tutorial and documentation at https://docs.python.org/ . -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Where is decorator in this example code?
On 14 November 2015 at 13:13, fl wrote: > On Saturday, November 14, 2015 at 7:11:11 AM UTC-5, fl wrote: >> Hi, >> >> I am learning decorator following this link: >> >> http://thecodeship.com/patterns/guide-to-python-function-decorators/ >> >> When I read decorator on class, I don't see decorator taking in effect. >> In the following code snippet, there is the same print out if I comment out >> two lines 'def p_decorate(func):' and '@p_decorate'. >> >> Can you tell me what role of decorator in this code? [snip code] > > My OP may not be clear enough. Here is the key question. After the function > definition, there is no obvious decorator application in the function call: > > my_person = Person() > print my_person.get_fullname() > > Where is the difference between the non-decorator and decorator in this > example? > > Thanks, > -- > https://mail.python.org/mailman/listinfo/python-list Have you tried executing the code with and without the decorator? $ python2 without-decorator.py John Doe $ python2 with-decorator.py John Doe Basically, the decorator wraps the output of your get_fullname function with HTML tags. (Running code examples is a great way to understand them.) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Using subprocess to capture a progress line
On 11 November 2015 at 17:16, Tim Johnson wrote: >> (2) [don’t do it] do you need to intercept the lines? If you don’t set >> stderr= and stdout=, things will print just fine. > Got to try that before using the module, just for edification. At which point your initial code sample will become: ### p = subprocess.Popen(list(args)) ### (is list(args) really necessary? Wouldn’t plain Popen(args) just work?) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Using subprocess to capture a progress line
On 10 November 2015 at 23:47, Tim Johnson wrote: > Using python 2.7.6 on ubuntu 14.04 > The application in question is run with bash and gnome-terminal : > > I've written a command-line "wrapper" for youtube-dl, executing > youtube-dl as a subprocess. > > -- > youtube-dl reports download progress on one line. I.E. the line is > overwritten numerous times with no carriage return until the > downloading is finished. > -- > > The following code runs the youtube-dl command and reports each line > as output by youtube-dl > ### > p = subprocess.Popen(list(args), stderr=subprocess.STDOUT, > stdout=subprocess.PIPE) > while True: > line = p.stdout.readline() > if not line: > break > tmp = line.strip() > print tmp > ### > > However this method not does show the download progress _until_ the > download is complete. There is no \n character at the end — which means that p.stdout.readline() cannot return. In fact, if you printed repr() of the line you read, you would get this: b'\r[download] 54.9% of 2.73MiB at 26.73KiB/s ETA 00:47\r[download] 55.0% of 2.73MiB at 79.33KiB/s ETA 00:15\r…snip…\r[download] 100% of 2.73MiB in 00:01\n' The download line is implemented using \r, which is the carriage return character (return to the first character), and then by overwriting characters that were already printed. The solution? There are numerous. I’ll help you by obscuring the worst one. (1) [recommended] figure out how to make youtube_dl work as a library, read its main file to figure out the problem. Don’t mess with subprocess. (2) [don’t do it] do you need to intercept the lines? If you don’t set stderr= and stdout=, things will print just fine. (3) [DON’T DO IT] .ernq() punenpgre ol punenpgre naq znxr n zrff. PS. Thank you for setting a sensible Reply-To header on your messages. Which is something the list should be doing. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there an archive of the gohlke python binaries on windows
On 8 November 2015 at 06:55, Sayth Renshaw wrote: > Just wondering if there is an archive mirror for these binaries available. i > was looking for lxml 3.4.1 and the current version is the latest on the page > at 3.4.4 being on windows I cannot build it. > > http://www.lfd.uci.edu/~gohlke/pythonlibs/ > > Thanks > > Sayth > -- > https://mail.python.org/mailman/listinfo/python-list Why do you need an old version? There should be no reason to use an old version… Why can’t you use lxml 3.4.4? If you are a fan of old software, you are probably on Python 2.x, too, and you can get a binary from here: https://pypi.python.org/pypi/lxml/3.4.1 Also, those binaries are built by someone USING Windows. You can certainly build C extensions, if you install Visual Studio in the correct version. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Guide in Deskop Application Development in Python for newbies
r interface. > > -- > https://mail.python.org/mailman/listinfo/python-list web2py is weird, Django is more fun. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Problems connecting to PostgreSQL
On 8 November 2015 at 00:40, Cecil Westerhof wrote: > I followed http://zetcode.com/db/postgresqlpythontutorial/. > > I used: > sudo -u postgres createuser stressTest > this create the role, but also gave: > could not change directory to "/root": Permission denied > and I did not get the questions. This is not an error, just a warning — and it comes from sudo, postgres doesn’t care. To silence it, you need to work from a different directory than /root. The commands actually worked just fine. > Then I used: > sudo -u postgres createdb stressTest -O stressTest > This gave also: > could not change directory to "/root": Permission denied > > The database is created, but when I execute: > conn = psycopg2.connect(database = postgres_database, user = 'stressTest') > I get: > psycopg2.OperationalError: FATAL: Peer authentication failed for user > "stressTest" > > What do I need to do to get things working? You need to configure your PostgreSQL database to use md5 authentication, and set a password for your user. # cd / # sudo -u postgres psql postgres=# ALTER ROLE stressTest WITH PASSWORD 'swordfish'; postgres=# \q # vim /var/lib/postgres/data/pg_hba.conf Change host settings to look like this: # IPv4 local connections: hostall all 127.0.0.1/32md5 # IPv6 local connections: hostall all ::1/128 md5 Then you can connect using: conn = psycopg2.connect(database='stressTest', user='stressTest', password='swordfish', host='localhost') Documentation: http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html http://www.postgresql.org/docs/current/static/auth-methods.html http://www.postgresql.org/docs/current/static/sql-alterrole.html (basically, the default peer authentication checks your Unix user name to see if it matches 'stressTest', and fails) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Questions on Pickle and Shelve
On 6 November 2015 at 12:53, Virgil Stokes wrote: > Here is snippet of Python (vers. 2.7.10) code that bothers me. > > [snip bad code] > > 1) Which (the pickle or shelve code) takes less total RAM, if dogs and cats > were very large? > 2) When the last shelve.open is given, is the entire contents of > shelve.data transferred to RAM? Note, if the print sfile is uncommented > then the entire contents of shelve.data is printed out. > > I was under the impression that the entire contents of a shelved file was > not transferred to RAM when it was opened. > > > -- > https://mail.python.org/mailman/listinfo/python-list 1) That does not matter. I do know that shelve files can grow larger over time though. 2) Shelve files are pickles in disguise. Which means they need to be loaded into memory, executing *arbitrary code*. Here’s a question for you: 3) Why are you using either? Both are unsafe and can lead to issues if you take untrusted files. Use JSON. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python PNG Viewer(Browser Based)
On 3 November 2015 at 12:54, Arshpreet Singh wrote: > Hello Everyone, > > I am looking for Browser-based PNG file viewer written in > Python.(Flask framework preferably) > > Following project(Flask-Based) provides many things(File manager as > well as file viewer) but it does not support PNG files. > > https://github.com/vmi356/filemanager > > Any idea if I have to write my own browser based PNG viewer from > scratch(Using PIL or other required library) > > On the other side if I have to write only Desktop-based only two lines > are enough to do many things: > > Like, > > from PIL import Image > f = Image.open("file.png").show() > > > But I am not getting right sense that how to make possible using Python+Flask. > > Hope I am able to tell my problem? > -- > https://mail.python.org/mailman/listinfo/python-list Your problem is lack of basic understanding of the Internet. Because EVERY graphical web browser supports PNG files NATIVELY. With a single tag. Just figure out where to add the PNG handler code and read any random “how to add images to a webpage” tutorial. You might need a new template and some code that is aware of the file being an image. But absolutely no PNG viewer is necessary. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: python doesn't install
On 2 November 2015 at 09:28, Dave Farrance wrote: > Yes, I've read the justifications. Why list all the non-supported OSs? > And the explanation about each version of Python being supported just > for the supported versions of Windows upon its release is in the > documentation -- somewhere. But it still seems to me that stating the > minimum requirements in a place that people would tend to look for it is > a... minimum requirement. > > If the developers really are determined not to mention specific versions > of Windows (If it was me, I'd have probably mentioned that the most > recent version required Vista somewhere on the download page), then > maybe adding the comment about matching the release date of Python to > the supported versions of Windows to the download pages would give > people some sort of clue as to what's going on. > -- > https://mail.python.org/mailman/listinfo/python-list This could be resolved in one line of HTML or reST. Windows XP is still in use, and it was supported one minor version ago. Surely it wouldn’t hurt to add a “Warning: Windows XP is ancient, and Python 3.5 does not support it — upgrade to a newer OS or use 3.4.3 instead” notice to the download page? -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: installer user interface glitch ?
On 1 November 2015 at 09:23, t_ciorba--- via Python-list wrote: > > hi, > i am not sure what is wrong, but after launching the installer for windows > XPsp3 python-3.5.0.exe i couldnt see what i have to select, it was a white > board and the only button on it was "cancel". here is a screen of it: Windows XP is not supported. Please upgrade to a modern version of Windows, or switch to Linux. (you could also use 3.4.3, but Windows XP is insecure, and more apps will follow suit.) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: pip trouble
On 30 October 2015 at 13:14, Neal Becker wrote: > I have a custom-compiled numpy 1.10.0. But as you see, pip wants to install > a new numpy, even though the requirement (numpy>=1.6) was already satisfied. > WTF? > > All are installed into --user. > > This is on fedora 22 linux. > > pip install --up --user matplotlib > Collecting matplotlib > Using cached matplotlib-1.5.0.tar.gz > Collecting numpy>=1.6 (from matplotlib) > Using cached numpy-1.10.1.tar.gz > Requirement already up-to-date: python-dateutil in > ./.local/lib/python2.7/site-packages (from matplotlib) > Collecting pytz (from matplotlib) > Using cached pytz-2015.7-py2.py3-none-any.whl > Collecting cycler (from matplotlib) > Using cached cycler-0.9.0-py2.py3-none-any.whl > Collecting pyparsing!=2.0.4,>=1.5.6 (from matplotlib) > Using cached pyparsing-2.0.5-py2.py3-none-any.whl > Collecting six>=1.5 (from python-dateutil->matplotlib) > Using cached six-1.10.0-py2.py3-none-any.whl > Installing collected packages: numpy, pytz, six, cycler, pyparsing, > matplotlib > Found existing installation: numpy 1.10.0 > DEPRECATION: Uninstalling a distutils installed project (numpy) has been > deprecated and will be removed in a future version. This is due to the fact > that uninstalling a distutils project will only partially uninstall the > project. > Uninstalling numpy-1.10.0: > Successfully uninstalled numpy-1.10.0 > Running setup.py install for numpy > > -- > https://mail.python.org/mailman/listinfo/python-list You used --up (aka -U, --upgrade). That option tries to upgrade the package you asked for *and* all dependencies. And since numpy 1.10.1 is newer than what you have installed, pip will try to install that. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Script To Remove Files Made Either By Python Or Git
On 9 October 2015 at 12:08, Joshua Stokes wrote: > Hi > > Is there an available script to remove file created by either using the > Python module or by using git? There’s no such script, but we could help you write one. Now, what “Python module” do you mean? Unless it’s a git module, it’s impossible. And I really hope that “by using git” really means “that are part of the git repo”. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: PySide window does not resize to fit screen
On 5 October 2015 at 13:20, Hedieh Ebrahimi wrote: > is this free to use for commercial use? > -- > https://mail.python.org/mailman/listinfo/python-list Yeah, you can use Qt Designer to create a nice layout and the pyside-uic tool to generate code (that you will need to clean up later). -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: PySide window does not resize to fit screen
On 2 October 2015 at 15:10, Hedieh Ebrahimi wrote: > Thanks Laura, > > In my user interface I have many group boxes that are located inside the main > widget. All the group boxes and their child widgets have fixed sizes. > > How can I use the width and height I get from availableGeometry or > ScreenGeometry to multiply > > screenGeometry = QApplication.instance().desktop().screenGeometry() > availGeometry = QApplication.instance().desktop().availableGeometry() > width, height = availGeometry.width(), availGeometry.height() > > to resize my geometry by a ratio? Is this a good approach? > -- > https://mail.python.org/mailman/listinfo/python-list This is NOT a good approach. A good approach involves using a layout. See my previous e-mail for details. Geometry is not going to help you here, especially since you would need a ton of code to resize everything on **any** window size change event. And you especially do not need the screen size, because it would still hinder changing window sizes. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: The Nikola project is deprecating Python 2.7 (+2.x/3.x user survey results)
On 2 October 2015 at 01:59, Terry Reedy wrote: > On 10/1/2015 12:26 PM, Chris Warrick wrote: >> >> The Nikola developers decided to deprecate Python 2.7 support. >> Starting with v7.7.2, Nikola will display a warning if Python 2.7 is >> used (but it will still be fully supported). In early 2016, Nikola >> v8.0.0 will come out, and that release will not support Python 2.7 >> officially. > > > How sane ;-) > >> The decision was made on the basis of a user survey, with 138 >> participants. The vast majority of them claimed that they either use >> Python 3 already, or can switch really easily. > > > From the survey and description below, 'using Python 3' means having Python > 3 installed, not writing Python 3 code. Correct? Correct. We asked about Nikola users, who don’t really have to write any Python code. This is, however, an useful information for OSS developers, who want to know if they can/should target Python 3 instead of Python 2. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: The Nikola project is deprecating Python 2.7 (+2.x/3.x user survey results)
On 1 October 2015 at 18:43, wrote: > Python 3 has venv in the kit. Is there a reason users should get the > virtualenv add-on? Both can be used; I wrote about virtualenv because it’s the tried-and-true solution (and is it guaranteed in all Linux distros anyway?) On 1 October 2015 at 19:02, Stefan Behnel wrote: > Chris Warrick schrieb am 01.10.2015 um 18:26: >> The Nikola developers decided to deprecate Python 2.7 support. > > I wonder why it took the Nikola project so long to take that decision. > Python 3.3 came out almost exactly three(!) years ago and seems to have all > major features that they would require. Nikola's PyPI page claims support > of Python 3.3 for just about as long, since version 5.4 or so, which means > that all of their dependencies were already available back then. > > It's a different thing for *libraries* that Python 2.x users still depend > on, but for an *application* that has all its (necessary) dependencies > available in Python 3.x, I can't see a general reason to keep supporting > both language versions. > > Stefan We did it now because it all started with frustration with 2.7 [0]. Also, doing it back in 2012/2013 would be problematic, because back then not all Linux distros had an easily installable Python 3 stack (and RHEL 7 still doesn’t have one in the default repos) [0]: http://ralsina.me/weblog/posts/floss-decision-making-in-action.html -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
The Nikola project is deprecating Python 2.7 (+2.x/3.x user survey results)
The Nikola developers decided to deprecate Python 2.7 support. Starting with v7.7.2, Nikola will display a warning if Python 2.7 is used (but it will still be fully supported). In early 2016, Nikola v8.0.0 will come out, and that release will not support Python 2.7 officially. The decision was made on the basis of a user survey, with 138 participants. The vast majority of them claimed that they either use Python 3 already, or can switch really easily. The main reason for the switch was the fact that supporting both requires a lot of extra effort, especially because Python 2.7’s Unicode support is abysmal. Full results: https://getnikola.com/blog/env-survey-results-and-the-future-of-python-27.html What is Nikola? === Nikola is a static site and blog generator, written in Python. It can use Mako and Jinja2 templates, and input in many popular markup formats, such as reStructuredText and Markdown — and can even turn Jupyter (IPython) Notebooks into blog posts! It also supports image galleries, and is multilingual. Nikola is flexible, and page builds are extremely fast, courtesy of doit (which is rebuilding only what has been changed). Find out more at the website: https://getnikola.com/ -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: PySide window does not resize to fit screen
On 1 October 2015 at 15:44, Hedieh Ebrahimi wrote: > Dear all, > > I am using Pyside to create a user interface for my app. > The app works fine on my computer with big screen, but when I take it to my > laptop with smaller screen size, it does not resize to match the screen size. > > How can I make my main widget get some information about the screen size and > resize automatically? > > Thanks in Advance for your answers. > -- > https://mail.python.org/mailman/listinfo/python-list The correct way to do this is to lay your application out using a layout. The available layouts are: * QHBoxLayout * QVBoxLayout * QGridLayout * QFormLayout The exact layout to use depends on your needs. What are you using to create your Qt code? Are you using Qt Designer or are you writing the code by hand? If you are using Qt Designer, use the “Lay Out…” buttons in the Form menu or on the tool bar. If you are writing Qt code by hand, it looks roughly like this (for a VBox; Grid and Form are more complicated as they involve positioning): lay = QtGui.QVBoxLayout(self) # your central widget, dialog, main window — whichever one exists btn = QtGui.QButton("Hello", lay) lay.addWidget(btn) Please check with Qt documentation for more details -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Fwd: Django Tutorial (Database setup) Question
Forwarding to list (forgot about this stupid reply all thing, sorry). -- Forwarded message -- From: Chris Warrick Date: 27 September 2015 at 19:50 Subject: Re: Django Tutorial (Database setup) Question To: Cai Gengyang On 27 September 2015 at 19:39, Cai Gengyang wrote: > http://pastebin.com/index/RWt1mp7F Looking through my code , can't seem > to find any errors yet. All the parentheses seem to be in place too, this is > weird ... > > On Mon, Sep 28, 2015 at 1:01 AM, Chris Warrick wrote: >> >> On 27 September 2015 at 18:18, Cai Gengyang wrote: >> > I believe I am already in the same directory that contains manage.py , >> > but I >> > still get an error (a syntax error). Checked the lines in settings.py >> > and >> > can't find anything wrong with them either. Posted my entire code below >> > : >> >> > File "/Users/CaiGengYang/mysite/mysite/settings.py", line 45 >> > 'django.middleware.csrf.CsrfViewMiddleware', >> > ^ >> > SyntaxError: invalid syntax >> >> There’s a typo on or before line 45. Pastebin your full settings.py >> file, and try looking for errors (like missing parentheses) yourself. >> >> -- >> Chris Warrick <https://chriswarrick.com/> >> PGP: 5EAAEA16 > > On further inspection, this might be a Django or Python problem… try re-installing Django. I don’t really know what could be wrong here. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: for loop
On 20 September 2015 at 09:55, shiva upreti wrote: > https://ideone.com/BPflPk > > Please tell me why 'print s' statement is being executed inside loop, though > I put it outside. > Please help. I am new to python. > -- > https://mail.python.org/mailman/listinfo/python-list You have mixed indentation. Your code contains both tabs and spaces. Python interprets tabs as 8 spaces, while your other indentation is 4 spaces, leading to bad parsing. Please make sure you use only spaces (reconfigure your editor to always insert 4 spaces and reindent everything with tabs) -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Can anyone help me run python scripts with http.server?
On 6 September 2015 at 13:50, wrote: > Hello everyone, > > I want to use python for web development but I > could not configure my Apache server to run python > with the guides I found on the internet. > > Can anyone help me configure http.server > to run python scripts? > > I ran the command python -m http.server --cgi to start the http server, > and if I put index.html, I will see the page but if I use > index.py, it doesn't show the page, I can only see the > directory listing of the files and when I click on > index.py, it doesn't run the code, I can see it just > like in the editor. > > Can anyone help me out? > > Thanks in advance. > -- > https://mail.python.org/mailman/listinfo/python-list Don’t use http.server. Don’t use CGI. This is not how things work in Python. In Python, you should use a web framework to write your code. Web frameworks include Flask, Django, Pyramid… Find one that’s popular and that you like, and learn that. You won’t have any `.py` URLs, instead you will have modern pretty URLs with no extensions. And a lot of things will be abstracted — no manual header creation, help with safe forms and databases. And then you will need to figure out how to run it. I personally use nginx and uwsgi for this, you may need to look for something else. Examples for Django: https://docs.djangoproject.com/en/1.8/#first-steps https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help w. PIP!
On 4 September 2015 at 15:14, Dennis Lee Bieber wrote: > On Fri, 4 Sep 2015 04:27:47 +0100, Mark Lawrence > declaimed the following: > > >>python3 just doesn't exist on Windows, it's always python.exe or > > Really? > > [snip] > 09/17/2013 12:37 AM40,448 python.exe > 09/17/2013 12:37 AM40,448 python3.3.exe > 09/17/2013 12:37 AM40,448 python3.exe > 09/17/2013 12:37 AM40,960 pythonw.exe > 09/17/2013 12:37 AM40,960 pythonw3.3.exe > 09/17/2013 12:37 AM40,960 pythonw3.exe > [snip] > > I did not create those variant files, they were part of my original > install from ActiveState. You are using an unofficial build of Python; the official one (from python.org) does not have `python3.exe`. -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: pip
On 31 August 2015 at 11:43, chenc...@inhand.com.cn wrote: > hi: > Python 2.7.9 and later (on the python2 series), and Python 3.4 and later > include pip by default.But i can not find it in python2.7.10 package. What's > the matter? How can i install pip on my Embedded device? > > > -- > https://mail.python.org/mailman/listinfo/python-list The inclusion is handled by the ensurepip module. Run this: python -m ensurepip -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: Trouble getting to windows My Documents directory
On 11 July 2015 at 02:24, wrote: > The My Documents directory is not guaranteed to be named "Documents". On > older versions of windows it was "My Documents", and on foreign versions > of windows it is a name in their language. That’s not necessarily “older”. Windows XP/7/8: My Documents Windows Vista/8.1: Documents As for localized versions, Vista and up do the translation in Windows Explorer but use English names on disk. …but even with all that, users (or their administrators) can move the My Documents folder away from the home directory (to a file server, for example). -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list
Re: [setuptools] install data-file in users home-dir
CC’ing the mailing list; please use Reply All in the future. On 10 July 2015 at 16:36, wrote: > Hi Chris, > > thank you for your answer. > > On 2015-07-10 09:39 Chris Warrick wrote: >> You should NEVER use sudo with pip. Instead, use virtualenvs as a >> regular user, or create your own .deb packages. > > I am not sure, but maybe this is an Ubuntu-specific "problem"? > When I don't use sudo I got errors like this > "PermissionError: [Errno 13] Permission denied: > '/usr/local/lib/python3.4/dist-packages/SQLAlchemy-1.0.6.dist-info" > > And it make sense for me. This is correct. Don’t install things system-wide with pip. > Don't tell me about deb-Packages! :D I am stuck with that currently. I > would be glad to have a correct working whl-file for my local needs. > After that - maybe! - I will start again with thinking about a deb. > > How can virtualenv help here? I need to install > python-software/packages to the system and not to a different > environment or sandbox. > I never used virtualenv but as I understand it it is for testing > purpose not for productive system. virtualenv should be used for both testing AND production environments. Your projects can have different versions of dependencies, and this is what virtualenv helps with: they are separate from each other. You can also modify the system packages without messing with your system packages. You can also use pip install --user to install to ~/.local >> And you should not create the files in your install script. Instead, >> install them to a different data dir (somewhere in 'share/appname' > > What do you mean with "data dir"? For a default config-file it could > be /etc/appname/default.conf. But I have no rights for that. https://pythonhosted.org/setuptools/setuptools.html#including-data-files Makes your package installable through wheel files and friendly for all environments. >> should copy this file to user’s config directory (use pkg_resources to >> help you get it) if it does not exist yet. > > I will look at this package. https://pythonhosted.org/setuptools/setuptools.html#accessing-data-files-at-runtime -- Chris Warrick <https://chriswarrick.com/> PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-list