Re: print without ()
On Thursday, 7 September 2017 07:14:57 UTC+1, Andrej Viktorovich wrote: > Sometimes I find code with strange print function usage. String is passed > without brackets. > > #!/usr/bin/python > list = ['physics', 'chemistry', 1997, 2000]; > print "Value available at index 2 : " > print list[2] > list[2] = 2001; > print "New value available at index 2 : " > print list[2] > > If I use command print "aaa" in console I get error. So, why this is allowed > in sample? > > Sample from: > https://www.tutorialspoint.com/python/python_lists.htm That's because of a difference between python 2 and python 3. In python 3, print is a function (which requires brackets). In python 2 it was a keyword. The tutorial you're looking at is from python 2. -- https://mail.python.org/mailman/listinfo/python-list
Re: nltk related issue
On 21/06/18 04:40, Sharan Basappa wrote: > Folks, > > I am trying to run a simple example associated with nltk. > I get some error and I don't know what the issue is. > I need some guidance please. > [...] > LookupError: > ** >Resource u'tokenizers/punkt/english.pickle' not found. Please >use the NLTK Downloader to obtain the resource: >>> >nltk.download() >Searched in: > - 'D:\\Users\\sharanb/nltk_data' > - 'C:\\nltk_data' > - 'D:\\nltk_data' > - 'E:\\nltk_data' > - 'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\nltk_data' > - 'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\lib\\nltk_data' > - 'D:\\Users\\sharanb\\AppData\\Roaming\\nltk_data' > - u'' > ** > As the error message says, you need to do a one-time installation of the NLTK data. See http://www.nltk.org/data.html for more info. Glenn -- https://mail.python.org/mailman/listinfo/python-list
Re: nltk related issue
To: Sharan Basappa From: Glenn Hutchings On 21/06/18 04:40, Sharan Basappa wrote: > Folks, > > I am trying to run a simple example associated with nltk. > I get some error and I don't know what the issue is. > I need some guidance please. > [...] > LookupError: > ** >Resource u'tokenizers/punkt/english.pickle' not found. Please >use the NLTK Downloader to obtain the resource: >>> >nltk.download() >Searched in: > - 'D:\\Users\\sharanb/nltk_data' > - 'C:\\nltk_data' > - 'D:\\nltk_data' > - 'E:\\nltk_data' > - 'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\nltk_d ata' > - 'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\lib\\n ltk_data' > - 'D:\\Users\\sharanb\\AppData\\Roaming\\nltk_data' > - u'' > ** > As the error message says, you need to do a one-time installation of the NLTK data. See http://www.nltk.org/data.html for more info. Glenn --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) -- https://mail.python.org/mailman/listinfo/python-list
[ANNOUNCE] pysudoku 0.1
Announcing PySuDoku version 0.1, yet another Sudoku program written in Python. But this one has features that I don't see in any of the others: * Cute interactive solving mode via Tkinter. * Puzzle generation option, for making your own puzzles. * Nicely packaged for installation via distutils. Sudoku, for the remaining 27 people in the world who don't know already, is a logic puzzle where you have to fill in the numbers in a 9x9 grid so that each row, column and 3x3 box has exactly one of the numbers 1-9 in them. You can get pysudoku at: http://www.freewebtown.com/zondo/programs -- http://mail.python.org/mailman/listinfo/python-list
[ANN] PySuDoku version 0.2
Announcing PySuDoku version 0.2, yet another Sudoku program written in Python, featuring: * Cute interactive solving mode via Tkinter. * Puzzle generation option, for making your own puzzles. * Nicely packaged for installation via distutils. New in this release: * Now uses psyco module, if available, for speedups. * There's now a hints message indicating how the number was deduced, courtesy of Paul Wayper <[EMAIL PROTECTED]>. Sudoku, for the remaining 27 people in the world who don't know already, is a logic puzzle where you have to fill in the numbers in a 9x9 grid so that each row, column and 3x3 box has exactly one of the numbers 1-9 in them. You can find PySuDoku at: http://www.freewebtown.com/zondo/programs -- http://mail.python.org/mailman/listinfo/python-list
Re: Pep8 in SetupTools
On Thursday, 12 December 2013 11:13:51 UTC, Chandru Rajendran wrote: > Please help me with running Pep8 using setuptools. Also help me how to Pep8 > for files in a folder. The tool you're looking for is flake8. It integrates with setuptools, so that you can run 'python setup.py flake8'. More information here: http://flake8.readthedocs.org/en/2.0/setuptools.html -- https://mail.python.org/mailman/listinfo/python-list
Re: Using virtualenv to bypass sudoer issues
On 06/02/14 17:32, Jean-Michel Pichavant wrote: > Assuming I have a debian workstation for which I don't have any sudo > rights, in order to be able to install / remove python packages, should > I be using virtualenv ? Is it a suited solution ? It depends on whether you need to share the installation with anyone else. If not, you could also install packages using: python setup.py install --user This will install in your home directory, in the '.local' subdirectory. And to run any scripts that get installed, add ~/.local/bin to your PATH. Glenn -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to use python 3.5
On Wednesday, 23 December 2015 12:46:43 UTC, Ankit Deshmukh wrote: > I am maters student in India, 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 might find the following useful (I had the same problem): http://stackoverflow.com/questions/2817869/error-unable-to-find-vcvarsall-bat -- https://mail.python.org/mailman/listinfo/python-list
Re: Python code in presentations
On Tuesday, 30 September 2014 12:51:00 UTC+1, Jean-Michel Pichavant wrote: > I'm currently writing a presentation to help my co-workers ramp up on new > features of our tool (written in python (2.7)). > > I have some difficulties presenting code in an efficient way (with some basic > syntax highlights). I need to be catchy about the code I'm presenting > otherwise the presentation will fail and I would be better saying to my > co-workers "RTFM", cause there is a manual. A good option is to use reStructuredText and the rst2s5 converter (http://docutils.sourceforge.net/docs/user/slide-shows.html). It can do syntax highlighting of python, and produces a slide show you display in a browser. An example of what you can produce is at http://farmdev.com/talks/unicode. Glenn -- https://mail.python.org/mailman/listinfo/python-list
Re: Code Review for Paper, Rock, Scissors
Hi there! Welcome to Python. On Tuesday, 14 October 2014 09:04:51 UTC+1, Revenant wrote: > I am new to Python and would also like to see if any of you programming > gurus have some suggestions about how I can simplify code, and also if > there are any other good starter programs to work on to improve my > skills. I'm sure you'll get a lot of helpful advice here. Here's a start: you have a lot of places where you're comparing variables to the capitalized and lower-case versions of the same string. You could halve that number if you converted your input to lowercase first. For example: if menuselection == 'play' or menuselection == 'Play': changes to: if menuselection.lower() == 'play': There are plenty of other string methods you might find useful. -- https://mail.python.org/mailman/listinfo/python-list
Re: python install on locked down windows box?
You could try Portable Python (http://www.portablepython.com). No need to install anything! -- http://mail.python.org/mailman/listinfo/python-list
Re: Python tools for managing static websites?
I haven't seen mention of HTMLgen, another python package. Check it out at: http://starship.python.net/crew/friedrich/HTMLgen/html/main.html Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: setup.py and file extensions like ".c++"
[EMAIL PROTECTED] wrote: > Is there any way to get setup.py to recognize file extensions like .c++ > in lieu of .cpp? I'd love to not have to rename the source files for > the library I'm trying to wrap in a python C extension. The python docs imply that the file extension is dealt with by the native C++ build system, so you have to use a recognized suffix (either .cpp or .cc, and possibly others). Looks like .c++ isn't a standard one. See http://docs.python.org/dist/describing-extensions.html#SECTION00232 Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple.index()
Nick Maclaren wrote: > Why doesn't the tuple type have an index method? It seems such a > bizarre restriction that there must be some reason for it. In fact, tuples have no non-__underscored__ methods at all. The list count() method would also be useful for tuples, since it doesn't modify anything. I have no idea why they aren't implemented either. Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple.index()
Simon Brunning wrote: > It's because, philosophically, a Python tuple isn't just a read-only list. But there are situations where you might want to treat it as a read-only list. E.g., an argument to a function, so that you can guarantee the function won't modify it. In that case, it makes sense for the non-modifying methods (index() and count()) to be available. -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple.index()
Roberto Bonvallet wrote: > list(my_arg).index(...) Absolutely -- you can work around the limitation without any problems. But the question is, why doesn't the list type share all its non-modifying methods with the tuple type? All the previous arguments about "homogenous" and "heterogenous" in this thread sound bogus to me. Python is first and foremost a practical language; what lists and tuples are supposedly "for" strikes me as being irrelevant. Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple.index()
Fredrik Lundh wrote: > if you cannot trust your own code not to modify objects you pass to it, > I'm not sure Python's the right language for you. It's not my own code I'm worried about. :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple.index()
Fredrik Lundh wrote: > if you don't want to understand the design, nobody can force you. but arguing > that the people behind the design "don't get it" isn't very practical. I'm not arguing that at all. What I'm saying is that from the perspective of someone not interested in design issues, it seems like an omission for tuples to be missing the non-modifying methods that lists have. Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple.index()
Nick Maclaren wrote: > I remain baffled. I accept the explanations, but what I am now > confused by is the reason for the explanations Maybe this archive posting, straight from the horse's mouth, will clear things up once and for all... http://www.python.org/search/hypermail/python-1992/0285.html Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter - resize tkMessageBox
On 4 Jun, 21:29, [EMAIL PROTECTED] wrote: > Is there a way to resize the width of the "tkMessageBox.askyesno" > dialog box, so that the text does not wrap to the next line. You can use the Tk option database, either explicitly or from a file. For example, to set the wrap length of all dialogs to 10 inches, try this: root = Tk() root.option_add("*Dialog.msg.wrapLength", "10i") Regards, Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: Need a Little Help on Tkinter and Python
On 6 Jun, 00:58, "W. Watson" <[EMAIL PROTECTED]> wrote: > is there a Tkinter intro manual somewhere Take a look at http://www.pythonware.com/library/tkinter/introduction Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: using tkinter to display html
On 20 Apr, 02:54, "Stephen M. Gava" <[EMAIL PROTECTED]> wrote: > yeah. i feel like i'm being forced to use wxwidgets/wxpython just because > i need pretty good html display though. You could always use a real web browser: import webbrowser webbrowser.open_new("index.html") Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter or wxpython?
On Aug 3, 1:00 am, "wang frank" <[EMAIL PROTECTED]> wrote: > I want to build a GUI to execut python script. I found TKinter and > wxpython. Which one is easier for a newbie? and which one is better? Well, Tkinter comes with Python, so newbies can get up and running straight away without having to download and install anything else. And there are probably lots more examples out there that a newbie can look at and learn from. As for *better*, wxPython has a lot more kinds of widgets in it, which will make writing GUIs less tedious in the long run, and the widgets look a lot nicer too. Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: Distinguishing attributes and methods
On Dec 8, 7:44 pm, MonkeeSage <[EMAIL PROTECTED]> wrote: > I think it muddies the water to say that a.a() and a.a are the same > thing--obviously they are not. A thing is not what it is; A thing is what it does. This is the Way of the Duck. -- Basho (in his "3 extra syllables" phase) -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI development with 3D view
On Dec 11, 1:58 am, gsal <[EMAIL PROTECTED]> wrote: > If all you need to do is display a bunch of arrows, as you mention, > the easiest thing to do might be to use Visual Python. It is > extremely easy to use. Another option, if your app is data-driven, is to check out the Visualization Toolkit (VTK) at http://www.vtk.org. It also has 3D graphics and a Python interface. Glenn -- http://mail.python.org/mailman/listinfo/python-list
How to create Pygments extension for Sphinx
Hi there Pythonistas... I'm writing documentation for a non-Python program using Sphinx (http://sphinx.pocoo.org), which is great. The program has an input file syntax suitable for highlighting using Pygments (http:// pygments.org), but, obviously, Pygments knows nothing about it. I've created a Pygments lexer which should highlight things, but how do I tell Pygments about the new lexer, short of manually adding the Python source to the Pygments "lexers" directory (clearly the Wrong Thing)? I've scoured Sphinx, Pygments and setuptools documentation, and seemingly the only way is to register a setuptools 'entry point' in the setup() function -- but that implies I'm installing a Python package, which I'm not. Do I have to create one, or is there another way? Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: who to thank for the new RST doc format?
On 18 Nov, 08:46, [EMAIL PROTECTED] wrote: > I am really loving the output, and have started using RST for some > of my own docs as well. > > It's wonderful and I know it was a lot of work on somebody's part > to think it through and make the changes. > > If it was you, Many Thanks!!! It *is* good, isn't it? Direct your thanks at the creator of Sphinx (http://sphinx.pocoo.org). -- http://mail.python.org/mailman/listinfo/python-list
Re: free chart lib for Python?
On Fri, 08 May 2009 10:27:08 +0800, oyster wrote: > I mean chart, not plot. If you don't know the difference, you can > check www.advsofteng.com, which is a commercial program > > is there such a thing with many kinds of chart, i.e. pie-chart, > line-chart, ..? You could try matplotlib: http://matplotlib.sourceforge.net. That can do all kinds of wizzo plotty/charty stuff. -- http://mail.python.org/mailman/listinfo/python-list
Re: import overwrites __name__
On Fri, 08 May 2009 19:14:52 +0200, Marco wrote: > I import a module and then the name space of the importing module seems do > be overwritten. > > my_name = __name__ > print my_name > print len(dir()) > from x import y as z > print __name__ > print len(dir()) > print my_name > > -> > __main__ > 119 > x > 117 > unhandled NameError "name 'my_name' is not defined" Interesting. Here's one possibility for the contents of module x.py: import sys del sys.modules['__main__'].my_name y = 42 I can't think of any other way apart from grovelling through sys.modules. Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: Graphics
vanam <[EMAIL PROTECTED]> writes: > hi all > i am new to python programming a beginner. I Came to know from the > groups that "How to think like a computer scientist" is preferable for > begineers. i just looking through that i came to one section where a > sample program for generation of graphics is present.i tried to copy > the same script to the interpreter and it is showing an error i want > to know whether is there anything that has to be installed in addition > to python 2.5 > below is the program > from gasp import * > begin_graphics() > Circle((200, 200), 60) > Line((100, 400), (580, 200)) > Box((400, 350), 120, 100) > end_graphics() You're probably getting an ImportError from the 'from gasp...' line. You need to grab and install the GASP package from https://launchpad.net/gasp. Glenn -- http://mail.python.org/mailman/listinfo/python-list
[ANN] PyStar 0.1 -- A* graph search algorithm
Announcing PyStar, a python module implementing the A* graph search algorithm. Available under the GPL, you can find it at http://fluffybunny.memebot.com/pystar.html I tried to find a decent Python version of this on the Interweb, but the only one I found (http://arainyday.se/projects/python/AStar) was just a bit too cryptic for me to understand and use. So I knocked this up from pseudocode on the Wikipedia A* page, and rewrote the AStar demo program in Tkinter. Comments, bug reports, big wads of cash, etc., are welcome. -- http://mail.python.org/mailman/listinfo/python-list
Re: calling source command within python
Jie <[EMAIL PROTECTED]> writes: > i'm having trouble executing os.system('source .bashrc') command > within python, it always says that source not found and stuff. Any > clue? There's no 'source' program; it's a shell builtin. Even if there was, it almost certainly wouldn't do what you want. The .bashrc file is supposed to contain settings applying to the current shell, and os.system() runs in a subshell, so the settings will only affect that shell. If you're doing this to set environment variables, try modifying os.environ instead. Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: Are rank noobs tolerated, here?
notbob <[EMAIL PROTECTED]> writes: > Am I likely to receive any help, here, or is there another irc, forum, etc, > that might better serve a complete amateur such as myself. Thnx. You're very likely to receive help here. Or at the very least, people will point you at the best place to get it. Fire away! Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: Numpy not found
adolfo <[EMAIL PROTECTED]> writes: > I downloaded and installed Phyton 2.52 (it works), numpy-1.0.4.win32- > py2.5, and scipy-0.6.0.win32-py2.5 > > I can´t get Numpy to show up at Python´s IDLE, or command line. If I > do: > > import Numeric > # I get > Traceback (most recent call last): > File "", line 1, in > import Numeric > ImportError: No module named Numeric Try 'import numpy' instead. Numeric is an earlier incarnation of numpy -- it has (mostly) the same interface, but is a different package. (Just to confuse things even further, there's also another old one, called numarray). > And if I do: > import Numeric * > # I get > SyntaxError: invalid syntax The proper syntax for that is (assuming you want numpy instead) 'from numpy import *'. Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: When to use try and except?
cnb <[EMAIL PROTECTED]> writes: > A ZeroDivisionError is better avoided wth an if-clause, don't you > think? It is a predictable exception... It depends. If zero-division is unlikely, then things would probably[*] run faster without checking. If speed is what you're interested in, that is... Glenn [*] Haven't checked, so don't really know :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Process "Killed"
dieter <[EMAIL PROTECTED]> writes: > I'm doing some simple file manipulation work and the process gets > "Killed" everytime I run it. No traceback, no segfault... just the > word "Killed" in the bash shell and the process ends. The first few > batch runs would only succeed with one or two files being processed > (out of 60) before the process was "Killed". Now it makes no > successful progress at all. Just a little processing then "Killed". > > Any Ideas? Is there a buffer limitation? Do you think it could be the > filesystem? > Any suggestions appreciated Thanks. > > The code I'm running: > == > > from glob import glob > > def manipFiles(): > filePathList = glob('/data/ascii/*.dat') > for filePath in filePathList: > f = open(filePath, 'r') > lines = f.readlines()[2:] > f.close() > f = open(filePath, 'w') > f.writelines(lines) > f.close() > print file Have you checked memory usage while your program is running? Your lines = f.readlines()[2:] statement will need almost twice the memory of your largest file. This might be a problem, depending on your RAM and what else is running at the same time. If you want to reduce memory usage to almost zero, try reading lines from the file and writing all but the first two to a temporary file, then renaming the temp file to the original: import os infile = open(filePath, 'r') outfile = open(filePath + '.bak', 'w') for num, line in enumerate(infile): if num >= 2: outfile.write(line) infile.close() outfile.close() os.rename(filePath + '.bak', filePath) Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: Query about doing fortran-esque repeat formatting
Rob Briggs mun.ca> writes: > Is there a way to do a repeat formatting command like in Fortran? Rather > that doing this: > > print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % > (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], > tmp[i][8], tmp[i][9]) There certainly is. You can use python's string concatenation and repeat operators: print "%s" + " %-5.3f" * 7 % Glenn -- http://mail.python.org/mailman/listinfo/python-list
Re: Overload print
On 25 Aug, 22:18, Ross Williamson wrote: > Is there anyway in a class to overload the print function? > > >> class foo_class(): > >> pass > >> cc = foo_class() > >> print cc > > Gives: > > <__main__.foo_class instance at > > > Can I do something like: > > >> class foo_class(): > >> def __print__(self): > >> print "hello" > >> cc = foo_class() > >> print cc > > Gives: > > hello Yes. Just define the __str__ method, like this: class foo_class(): def __str__(self): return "hello" -- http://mail.python.org/mailman/listinfo/python-list
Re: How to package my project and make it ready to be installed by using pip
On Monday, 20 March 2017 11:36:34 UTC, Daiyue Weng wrote: > Hi, I using Python 3.5.2 on Linux Mint 18.1, and I am wondering how to > package my PyCharm Python project as a module so that it can installed by > someone else by using pip. Like what tools and script I need to use or > write in order to do that. A good place to start is https://packaging.python.org. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to package my project and make it ready to be installed by using pip
On Monday, 20 March 2017 17:21:04 UTC, Daiyue Weng wrote: > If I tried > > pip3 install git+https://user_n...@bitbucket.org/user_name/project_name.git > > the package would get installed, but there are no python files that have > been installed in /usr/local/lib/python3.5/dist-packages/project_name > > Hence I couldn't import any class in the package in python. > > I am wondering how to fix this. Where are the files that did get installed? It's possible they were put somewhere you're not expecting. (Not, I hope, in a folder called 'project_name.git' -- that would be rather unhelpful!) -- https://mail.python.org/mailman/listinfo/python-list