divide
I have three points in a rectangle and i wonder how to use PYTHON to divide the rectangle into three parts with each point located in the different part. For instance, Point A goes to Part I, Point B goes to Part II and Point C goes to Part III. And the distance between any point within Part I and Point A is smaller than to Point B and Point C. And the similar rule applies to Part II and Part III. Thanks for any idea. -- http://mail.python.org/mailman/listinfo/python-list
is there any Python code for spatial tessellation?
is there any Python code for spatial tessellation? thanks a lot! -- http://mail.python.org/mailman/listinfo/python-list
Re: is there any Python code for spatial tessellation?
is there any course website about teaching python? for instance, some computer science courses website? On 10/8/05, Shi Mu <[EMAIL PROTECTED]> wrote: > is there any Python code for spatial tessellation? > thanks a lot! -- http://mail.python.org/mailman/listinfo/python-list
line
There are four points with coordinates: 2,3;4,9;1,6;3,10. How to use Python to draw one perpendicular bisector between (2,3) and (4,9); the other perpendicular bisector between (1,6)和(3,10); then, makes the output like: l1 a b c l2 a b c (Note: l indicates the perpendicular bisector with equation ax + by = c.) Plus the intersection coordinates of the two perpendicular bisectors: x,y -- http://mail.python.org/mailman/listinfo/python-list
Re: line
it is not a homework, just interested. On 10 Oct 2005 00:04:23 -0700, gsteff <[EMAIL PROTECTED]> wrote: > Why do you want to know? This list isn't a tool to get others to do > your homework. > > Greg > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
output
After I run the following python code, I expect to have the printing such as: The year is 2005 However, I got something like: The year is 2005 Fri Oct 14 17:43:31 2005 Fri Oct 14 17:43:31 2005 The year is 2005 What is the reason? The code follows: import time import now class today(now.now): def __init__(self, y = 1970): now.now.__init__(self) def update(self,tt): if len(tt) < 9 : raise TypeError if tt[0] < 1970 or tt[0] > 2038: raise OverflowError self.t = time.mktime(tt) self(self.t) if __name__ == "__main__": n = today() print "The year is", n.year -- http://mail.python.org/mailman/listinfo/python-list
path
I have installed Python 2.3 and I type "help()" and then "Keywords". I get a list of words. And it says that I can enter any of the words to get more help. I enter "and" and I get the following error message: "Sorry, topic and keyword documentation is not available because the Python HTML documentation files could not be found. If you have installed them, please set the environment variable PYTHONDOCS to indicate their location." but I have set both the environment variable, with the path to be C:\Python23\Doc which includes python23.chm Why I still got the above error message? -- http://mail.python.org/mailman/listinfo/python-list
path
I have installed Python 2.3 and I type "help()" and then "Keywords". I get a list of words. And it says that I can enter any of the words to get more help. I enter "and" and I get the following error message: "Sorry, topic and keyword documentation is not available because the Python HTML documentation files could not be found. If you have installed them, please set the environment variable PYTHONDOCS to indicate their location." but I have set both the environment variable, with the path to be C:\Python23\Doc which includes python23.chm Why I still got the above error message? -- http://mail.python.org/mailman/listinfo/python-list
Re: path
what is the differenc ebetween index and find in the module of string? for both "find" and "index", I got the position of the letter. -- http://mail.python.org/mailman/listinfo/python-list
index and find
what is the difference between index and find in the module of string? for both "find" and "index", I got the position of the letter. On 10/19/05, Shi Mu <[EMAIL PROTECTED]> wrote: > I have installed Python 2.3 and I type "help()" and then "Keywords". > I get a list of words. And it says that I can enter any of the words > to get more help. I enter > "and" and I get the following error message: > "Sorry, topic and keyword documentation is not available because the Python > HTML documentation files could not be found. If you have installed them, > please set the environment variable PYTHONDOCS to indicate their location." > > but I have set both the environment variable, with the path to be > C:\Python23\Doc which includes python23.chm > Why I still got the above error message? > -- http://mail.python.org/mailman/listinfo/python-list
ABOUT FIND
I got confused by the following information from the help for "FIND": find(s, *args) find(s, sub [,start [,end]]) -> in what does *args mean (especially the '*')? also, in the sub, why put a comma before start? what does 'in' mean? -- http://mail.python.org/mailman/listinfo/python-list
Print in PythonWin
In the PythonWin's interactive window, why sometimes I need type the command two times to make it work? for example, I execute "print testList" two times to make it work. Why? >>> print testList >>> print testList ['w', 'e', ' ', 'w', 'a', 'n', 't', ' ', 't', 'o', ' ', 'l', 'e', 'a', 'r', 'n', ' ', 'p', 'y', 't', 'h', 'o', 'n'] -- http://mail.python.org/mailman/listinfo/python-list
difference after remove
Is there any difference if I remove the '/' from the following statement? intMatrix2 = [[1,1,2,4,1,7,1,7,6,9],\ [1,2,5,3,9,1,1,1,9,1],\ [0,0,5,1,1,1,9,7,7,7]] print intMatrix2 I removed one '\' and it still works. So what is the use of '\'? -- http://mail.python.org/mailman/listinfo/python-list
pickle
I got a sample code and tested it but really can not understand the use of pickle and dump: >>> import pickle >>> f = open("try.txt", "w") >>> pickle.dump(3.14, f) >>> pickle.dump([1,2,3,4], f) >>> f.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: pickle
what does the following code mean? y = pickle.load(file("cnumber.pickle", "r")) also, I can not understand "f" in pickle.dump(x, f) On 10/25/05, marduk <[EMAIL PROTECTED]> wrote: > On Mon, 2005-10-24 at 23:55 -0700, Shi Mu wrote: > > I got a sample code and tested it but really can not understand the > > use of pickle and dump: > > > > >>> import pickle > > >>> f = open("try.txt", "w") > > >>> pickle.dump(3.14, f) > > >>> pickle.dump([1,2,3,4], f) > > >>> f.close() > > The pickle module "serializes" python objects. You can "dump" a python > object that can later be loaded: > > >>> x = complex(2,3.5) > >>> f = open("cnumber.pickle", "w") > >>> import pickle > >>> pickle.dump(x, f) > >>> f.close() > >>> y = pickle.load(file("cnumber.pickle", "r")) > >>> y > (2+3.5j) > > > -- http://mail.python.org/mailman/listinfo/python-list
cell and row
I can not understand the use of "cell" and "row" in the code: # convert the matrix to a 1D list matrix = [[13,2,3,4,5],[0,10,6,0,0],[7,0,0,0,9]] items = [cell for row in matrix for cell in row] print items -- http://mail.python.org/mailman/listinfo/python-list
Re: cell and row
In the follwoing code, Why the result is "'defenestrate', 'window', 'defenestrate', " before the original list instead of 'defenestrate', 'window', ? >>> a = ['defenestrate', 'cat', 'window', 'defenestrate'] >>> for x in a[:]: ... if len(x) > 4: a.insert(0, x) ... >>> a ['defenestrate', 'window', 'defenestrate', 'defenestrate', 'cat', 'window', 'defenestrate'] On 10/25/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Shi Mu wrote: > > >I can not understand the use of "cell" and "row" in the code: > > > > # convert the matrix to a 1D list > > matrix = [[13,2,3,4,5],[0,10,6,0,0],[7,0,0,0,9]] > > items = [cell for row in matrix for cell in row] > > print items > > working through the Python tutorial might be a good idea. here's the section > on list comprehensions: > > http://docs.python.org/tut/node7.html#SECTION00714 > > and here's the section on for loops: > > http://docs.python.org/tut/node6.html#SECTION00620 > > briefly: > >items = [cell for row in matrix for cell in row] > > or, slightly edited for clarity: > >items = [(cell) >for row in matrix >for cell in row] > > is the same thing as: > >items = [] >for row in matrix: >for cell in row: >items.append(cell) > > except that it's a bit shorter, and a bit more efficient. > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Tk
When I run the following code, script kept running and I have to force it to stop. Could you check the code to give suggestions how to improve it? Thanks a lot! from Tkinter import * from Tkinter import _cnfmerge class Dialog(Widget): def __init__(self, master=None, cnf={}, **kw): cnf = _cnfmerge((cnf, kw)) self.widgetName = '__dialog__' Widget._setup(self, master, cnf) self.num = self.tk.getint( apply(self.tk.call, ('tk_dialog', self._w, cnf['title'], cnf['text'], cnf['bitmap'], cnf['default']) + cnf['strings'])) try: Widget.destroy(self) except TclError: pass def destroy(self): pass if __name__ == '__main__': q = Button(None, {'text': 'How are you', Pack: {}}) b1 = Listbox() b1.pack() c1 = Checkbutton(text="Check") c1.pack() q.mainloop() from Tkinter import * root =Tk() menu=Menu(root) root.config(menu=menu) filemenu=Menu(menu) menu.add_cascade(label="Test", menu=filemenu) filemenu.add_command(label="Just Try") filemenu.add_separator() mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: Tk
How can I make the main menu come first, and after clicking test/just try, "how are you" interface shows. Thanks a lot! from Tkinter import * from Tkinter import _cnfmerge class Dialog(Widget): def __init__(self, master=None, cnf={}, **kw): cnf = _cnfmerge((cnf, kw)) self.widgetName = '__dialog__' Widget._setup(self, master, cnf) self.num = self.tk.getint( apply(self.tk.call, ('tk_dialog', self._w, cnf['title'], cnf['text'], cnf['bitmap'], cnf['default']) + cnf['strings'])) try: Widget.destroy(self) except TclError: pass def destroy(self): pass if __name__ == '__main__': q = Button(None, {'text': 'How are you', Pack: {}}) b1 = Listbox() b1.pack() c1 = Checkbutton(text="Check") c1.pack() q.mainloop() from Tkinter import * root =Tk() menu=Menu(root) root.config(menu=menu) filemenu=Menu(menu) menu.add_cascade(label="Test", menu=filemenu) filemenu.add_command(label="Just Try") filemenu.add_separator() mainloop() -- http://mail.python.org/mailman/listinfo/python-list
click event
I have the following workable code and every time i click on the canvas, the coordinates are reported. i wonder how i can draw the lines when i click the canvas using these coordinates? from Tkinter import * root = Tk() c = Canvas(root, bg='#0e2e0e', height=500, width=1000) def click(event): print event.x, event.y frame = c c.bind('',click) c.pack() root.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
image
why the following code report the error: Traceback (most recent call last): File "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Python23\Examples\AppB\text.py", line 24, in ? text.image_create(END, image=photo) File "C:\Python23\lib\lib-tk\Tkinter.py", line 2882, in image_create return self.tk.call( TclError: image "pyimage4" doesn't exist from Tkinter import * root = Tk() root.option_readfile('optionDB') root.title('Text') text = Text(root, height=26, width=50) scroll = Scrollbar(root, command=text.yview) text.configure(yscrollcommand=scroll.set) text.tag_configure('bold_italics', font=('Verdana', 12, 'bold', 'italic')) text.tag_configure('big', font=('Verdana', 24, 'bold')) text.tag_configure('color', foreground='blue', font=('Tempus Sans ITC', 14)) text.tag_configure('groove', relief=GROOVE, borderwidth=2) text.tag_bind('bite', '<1>', lambda e, t=text: t.insert(END, "I'll bite your legs off!")) text.insert(END, 'Something up with my banter, chaps?\n') text.insert(END, 'Four hours to bury a cat?\n', 'bold_italics') text.insert(END, 'Can I call you "Frank"?\n', 'big') text.insert(END, "What's happening Thursday then?\n", 'color') text.insert(END, 'Did you write this symphony in the shed?\n', 'groove') button = Button(text, text='I do live at 46 Horton terrace') text.window_create(END, window=button) photo=PhotoImage(file='img52.gif') text.image_create(END, image=photo) text.insert(END, 'I dare you to click on this\n', 'bite') text.pack(side=LEFT) scroll.pack(side=RIGHT, fill=Y) root.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: image
yes. I use both cmd and pythonwin to run it. why both of them can not work? On 11/8/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Shi Mu wrote: > > > why the following code report the error: > > Traceback (most recent call last): > > File > > "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", > > line 310, in RunScript > >exec codeObject in __main__.__dict__ > > File "C:\Python23\Examples\AppB\text.py", line 24, in ? > >text.image_create(END, image=photo) > > File "C:\Python23\lib\lib-tk\Tkinter.py", line 2882, in image_create > >return self.tk.call( > > TclError: image "pyimage4" doesn't exist > > works for me, when running it from a stock CPython interpreter. > > have you tried running the script outside the pywin environment? > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
any python module to calculate sin, cos, arctan?
any python module to calculate sin, cos, arctan? -- http://mail.python.org/mailman/listinfo/python-list
parabola
Is there any sample code to draw parabola using Tkinter? -- http://mail.python.org/mailman/listinfo/python-list
triangulation
is there any sample code to triangulation? many thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: triangulation
Delaunay triangulations On 11/9/05, Robert Kern <[EMAIL PROTECTED]> wrote: > Shi Mu wrote: > > is there any sample code to triangulation? many thanks! > > Triangulation of what? Scattered points in a plane? 2D manifolds > embedded in a 3D space? > > Delaunay triangulations? Constrained triangulations? > > -- > Robert Kern > [EMAIL PROTECTED] > > "In the fields of hell where the grass grows high > Are the graves of dreams allowed to die." > -- Richard Harter > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] triangulation
On 11/10/05, Alex Hunsley <[EMAIL PROTECTED]> wrote: > Alan Gauld wrote: > > >>As in Pythagoras? > >> > >> > > > > > > > >>Or as in triangulation on a 2D surface, navigation etc.? > >> > >> > > > > > > > >>Or, do you mean radio triangulation by directional signal propagation > >> > >> > > > > > > > >>Or, do you mean drawing a triangle in Tkinter? > >> > >> > > > >Or even triangulation of currency from EU currency to EU currency > >via the euro? > > > >See: > >http://www.sysmod.com/eurofaq.htm#Triangulation > > > >Alan G. > > > > > This Shi Mu character is a little frustrating. They won't even respond > to peoples polite responses for clarification > Hit'n'run help requests. > > > the Internet is down for one day and so wonderful to have so many responses. i have checked all the links you guys mentioned. what i want is delaunay triangulation and the available ones online are written in C, Java and FORTRAN. I want to see some in Python because it is hard for me to figure out using python to do Fortune's sweeping line algorithm. Is python is not good in doing that kind of computation or some other reason? Thanks a lot for all of your responses!!! -- http://mail.python.org/mailman/listinfo/python-list
about widget construction kit
I tried to install WCK(Widget Construction Kit (WCK)): C:\Python23>python tkinter3000-1.0-20031212\setup.py install Traceback (most recent call last): File "tkinter3000-1.0-20031212\setup.py", line 23, in ? WCK_VERSION = setuplib.find_version("WCK/__init__.py") File "C:\wget2\tkinter3000-1.0-20031212\setuplib.py", line 74, in find_version for line in open(filename).readlines(): IOError: [Errno 2] No such file or directory: 'WCK/__init__.py' I checked my files and found there is a __init__.py and got confused why the error came out? On 11/11/05, Salvatore Di Dio <[EMAIL PROTECTED]> wrote: > If you mean trigonometrics calculus > give a try at > http://online.effbot.org/2004_09_01_archive.htm#tkinter-complex > and download too WCK http://effbot.org/zone/tkinter-index.htm > there is a demo on Lissajou > > Regards > > Shi Mu a écrit : > > >is there any sample code to triangulation? many thanks! > > > > > > > > > > > -- http://mail.python.org/mailman/listinfo/python-list
Re: about widget construction kit
On 11/11/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Shi Mu wrote: > > > I tried to install WCK(Widget Construction Kit (WCK)): > > > > C:\Python23>python tkinter3000-1.0-20031212\setup.py install > > Traceback (most recent call last): > > File "tkinter3000-1.0-20031212\setup.py", line 23, in ? > > WCK_VERSION = setuplib.find_version("WCK/__init__.py") > > File "C:\wget2\tkinter3000-1.0-20031212\setuplib.py", line 74, in > > find_version > > for line in open(filename).readlines(): > > IOError: [Errno 2] No such file or directory: 'WCK/__init__.py' > > > > I checked my files and found there is a __init__.py and got confused > > why the error came out? > > if you're using windows, please use a prebuilt version of the WCK. > > I also recommend using the 1.1b1 release; it's a lot better than 1.0. > > if you really want to build it yourself, and you have the right compilers > and all Tcl/Tk build files in the right places, change to the source directory > before running the setup script. if I run python command, I need to go to the directory where python is installed, so how can I change to the source directory at the same time? -- http://mail.python.org/mailman/listinfo/python-list
Re: directory listing
On 11 Nov 2005 22:00:04 GMT, Michael Konrad <[EMAIL PROTECTED]> wrote: > Richard Townsend <[EMAIL PROTECTED]> wrote: > > > On 11 Nov 2005 21:20:33 GMT, SU News Server wrote: > > > > Try passing the full pathname of each item to os.path.isdir() > > > > You can create the pathname using os.path.join(directory, x) > > > > > > > > I wonder if I can join ./, so I don't have the full path in each > entry? > > Thank you for responding. > _Michael > > > -- > http://mail.python.org/mailman/listinfo/python-list > I tried this and no error reported but nothing appear on the console, why? import os def buildList( directory='c:\TEMP' ): dirs = [ ] listing = os.listdir(directory) for x in listing: x = os.path.join(directory, x) print x if os.path.isdir(x): dirs.append(x) return dirs -- http://mail.python.org/mailman/listinfo/python-list
Re: directory listing
On 11/11/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Shi Mu wrote: > > > I tried this and no error reported but nothing appear on the console, why? > > > > import os > > > > def buildList( directory='c:\TEMP' ): > > dirs = [ ] > > listing = os.listdir(directory) > > for x in listing: > > x = os.path.join(directory, x) > > print x > > if os.path.isdir(x): > > dirs.append(x) > > return dirs > > is that the entire script? you're defining a function, but you're > not calling it. try adding > >print buildList() > > at the end of the script. It works but i am curious why the line of "print x" does not show anything. many thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: about widget construction kit
On 11/11/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Shi Mu wrote: > > > > > I tried to install WCK(Widget Construction Kit (WCK)): > > > > > > > > C:\Python23>python tkinter3000-1.0-20031212\setup.py install > > > > Traceback (most recent call last): > > > > File "tkinter3000-1.0-20031212\setup.py", line 23, in ? > > > > WCK_VERSION = setuplib.find_version("WCK/__init__.py") > > > > File "C:\wget2\tkinter3000-1.0-20031212\setuplib.py", line 74, in > > > > find_version > > > > for line in open(filename).readlines(): > > > > IOError: [Errno 2] No such file or directory: 'WCK/__init__.py' > > > > > > > > I checked my files and found there is a __init__.py and got confused > > > > why the error came out? > > > > > > if you're using windows, please use a prebuilt version of the WCK. > > > > > > I also recommend using the 1.1b1 release; it's a lot better than 1.0. > > > > > > if you really want to build it yourself, and you have the right compilers > > > and all Tcl/Tk build files in the right places, change to the source > > > directory > > > before running the setup script. > > > if I run python command, I need to go > > to the directory where python is installed, so how can I change to the > > source directory at the same time? > > you're 100% sure that you have a working compiler and the right Tcl/Tk > build files in the right place, but you don't know how to run an executable > from another directory? > > hmm. > > here are three ways: > > 1. pass in the full path to the executable: > >cd tkinter3000-1.0-20031212 >c:\python23\python setup.py install > > 2. add the python installation directory to the path. random > google link: > >http://www.computerhope.com/issues/ch000549.htm > > when you've updated the environment, open up a new command > window, and do > >cd tkinter3000-1.0-20031212 >python setup.py install > > 3. if you used a python.org installer, it's likely that you can run > the setup.py file directly: > >cd tkinter3000-1.0-20031212 >setup.py install > still confused by th first way you mentioned. If I cd tkinter3000-1.0-20031212, i will be enter the directory witht hte setup.py; for example, it is located as c:\temp\tkinter3000-1.0-20031212\setup.py However, I need to use c:\python23\python setup.py install to process the installation, how did python know where the file of "setup.py" located? -- http://mail.python.org/mailman/listinfo/python-list
Re: directory listing
On 11/11/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > "Shi Mu" wrote: > > > but i am curious why the line of "print x" does not show > > anything. > > because your c:\temp directory is empty ? > > print buildList() gets lots of stuffs from my temp directory(there do exist lots of files). But why "print x' has nothing? -- http://mail.python.org/mailman/listinfo/python-list
x, y coordinates in Tkinter canvas
got confused by x, y coordinates in Tkinter canvas. from left to right, does X increase? from top to bottom, does y increase? -- http://mail.python.org/mailman/listinfo/python-list
Re: about widget construction kit
On 11 Nov 2005 16:06:37 -0800, Martin Miller <[EMAIL PROTECTED]> wrote: > Shi Mu wrote: > > On 11/11/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > > > 1. pass in the full path to the executable: > > > > > >cd tkinter3000-1.0-20031212 > > >c:\python23\python setup.py install > > > ... > > > > > still confused by th first way you mentioned. If I cd > > tkinter3000-1.0-20031212, i will be enter the directory witht hte > > setup.py; for example, it is located as > > c:\temp\tkinter3000-1.0-20031212\setup.py > > However, I need to use c:\python23\python setup.py install to process > > the installation, how did python know where the file of "setup.py" > > located? > > Since a full path was not given for the 'setup.py' file in the second > line, it will be assumed to be in the current directory which was set > by the 'cd' command in the first line. > > HTH I tried again and got the follwoing message: *** cannot find Tcl/Tk headers and library files change the TCL_ROOT variable in the setup.py file but i have already installed TCL under python23 -- http://mail.python.org/mailman/listinfo/python-list
Re: about widget construction kit
very hard for me to understand the difference between try...except and try...finally -- http://mail.python.org/mailman/listinfo/python-list
about try statement
very hard for me to understand the difference between try...except and try...finally -- http://mail.python.org/mailman/listinfo/python-list
about array,arange
i got confused by the use of array and arange. arange get array and range get list, why we need the two different types? -- http://mail.python.org/mailman/listinfo/python-list
Re: about array,arange
On 11/12/05, Robert Kern <[EMAIL PROTECTED]> wrote: > Shi Mu wrote: > > i got confused by the use of array and arange. > > arange get array and range get list, why we need the two different types? > > When you're asking questions about a third-party module, it's a good > idea to mention the module. In this case you're asking about scipy_core > (hopefully) or else numarray or Numeric. > > The answer to your question is that sometimes we need to get largish > arrays (not lists) of consecutive numbers quickly. array(range(N)) is > wasteful of memory and time because it has to create a list of Python > ints that are simply going to be thrown away once we're done converting > to the needed array. > > -- > Robert Kern > [EMAIL PROTECTED] sorry to forget to mention the module name : Numeric -- http://mail.python.org/mailman/listinfo/python-list
Re: about widget construction kit
On 11/12/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Shi Mu wrote: > > > I tried again and got the follwoing message: > > *** cannot find Tcl/Tk headers and library files > > change the TCL_ROOT variable in the setup.py file > > but i have already installed TCL under python23 > > hmm. I still think it would be easier if you used a prebuilt version, like > everyone else. > > (if you insist on using an old source release instead of the latest binaries, > follow the instructions, and make sure the TCL_ROOT variable points to > the location of the Tcl/Tk development libraries (the directory that con- > tains Tcl's "include" and "lib" directories, that is)) what is Tcl/Tk development libraries? I have a tcl folder under c:\python23. Is that what you mean? Regards, -- http://mail.python.org/mailman/listinfo/python-list
Re: about array,arange
On 11/12/05, Robert Kern <[EMAIL PROTECTED]> wrote: > Shi Mu wrote: > > i got confused by the use of array and arange. > > arange get array and range get list, why we need the two different types? > > When you're asking questions about a third-party module, it's a good > idea to mention the module. In this case you're asking about scipy_core > (hopefully) or else numarray or Numeric. > > The answer to your question is that sometimes we need to get largish > arrays (not lists) of consecutive numbers quickly. array(range(N)) is > wasteful of memory and time because it has to create a list of Python > ints that are simply going to be thrown away once we're done converting > to the needed array. > > -- > Robert Kern > [EMAIL PROTECTED] still not clear. can you give an example? Thanks! it is from numeric module (really confused by the documentation) -- http://mail.python.org/mailman/listinfo/python-list
Re: directory listing
thanks a lot! On 11/11/05, Michael Konrad <[EMAIL PROTECTED]> wrote: > > This is what I decided on for a solution. I haven't tested it > cross-platform yet. > > import os > > def dirListing(directory='/Users/mkonrad'): >"""Returns a list of directories.""" >#variables >dirs = [] #list of directories > >#list of directories and files >listing = os.listdir(directory) > >#get just the directories >for x in listing: >if os.path.isdir(directory+os.sep+x): > dirs.append(x) > >return dirs > > Fredrik Lundh wrote: > > "Shi Mu" wrote: > > > >> print buildList() gets lots of stuffs from my temp directory(there do > >> exist lots of files). > >> But why "print x' has nothing? > > > > C:\>more script.py > > import os > > > > def buildList( directory='c:\TEMP' ): > > dirs = [ ] > > listing = os.listdir(directory) > > for x in listing: > > x = os.path.join(directory, x) > > print x > > if os.path.isdir(x): > > dirs.append(x) > > return dirs > > > > print buildList() > > > > C:\>dir temp > > ... > > > > 2005-11-12 00:00 . > > 2005-11-12 00:00 .. > > 2005-11-12 00:00 20 bacon.dat > > 2005-11-12 00:00 egg > > 2005-11-12 00:00 20 spam.txt > >2 fil(er) 40 byte > >3 katalog(er) 9 818 021 888 byte ledigt > > > > C:\>python script.py > > c:\TEMP\bacon.dat > > c:\TEMP\egg > > c:\TEMP\spam.txt > > ['c:\\TEMP\\egg'] > > > > > > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: compare list
> Hey Ben, > > first, as expected, the other two answers you received are better. :-) > > Sets are much better optimized for things like membership testing than > are lists. I'm not competent to explain why; indeed, I keep > overlooking them myself :-( > > Unfortunately, the indents got screwed up along the way. But the part > of my code you asked about was: > > for item in list1: > if item in list2: > if item + 1 in list1 and item + 1 in list2: > return True > > In some detail: > > Consider each item in list1 in turn. If the item isn't in list2, move > on, as there is no chance of it meeting your test. If the item is in > list2, then it is pointful to check if your test is met. Given that > you wanted consecutive numbers, the 'if item + 1 in list1 and item + 1 > in list2' condition checks if both lists (which contain item if we've > gone this far) also contain item + 1. If they do, you wanted the > function to return 1 (I changed it to True as more idiomatic). After > my for loop is a return False which we will only hit if the condition > you wanted to test was never satisfied. > > Does that clarify it? > > Finally, your response to Alex would have been much more useful if > you'd quoted the error rather than just asserting that you got an > error :-) > > Best, > > Brian vdB is it possible to modify the codes to compare the two lists with not necessarily consecutive numbers? For example, lisA=[1,2,5,9] lisB=[9,5,0] compare A and b will get true because the two lists have 5 and 9 together though they are indifferent order. Best Regards, Robert -- http://mail.python.org/mailman/listinfo/python-list
Re: compare list
On 11/15/05, Brian van den Broek <[EMAIL PROTECTED]> wrote: > Shi Mu said unto the world upon 2005-11-15 01:30: > >>Hey Ben, > >> > >>first, as expected, the other two answers you received are better. :-) > >> > >>Sets are much better optimized for things like membership testing than > >>are lists. I'm not competent to explain why; indeed, I keep > >>overlooking them myself :-( > > > > >> > >>Best, > >> > >>Brian vdB > > > > is it possible to modify the codes to compare the two lists with not > > necessarily consecutive numbers? > > For example, > > lisA=[1,2,5,9] > > lisB=[9,5,0] > > compare A and b will get true because the two lists have 5 and 9 > > together though they are indifferent order. > > Best Regards, > > Robert > > > > Sure, but rather than repair a less than best first approach, better > to do it with sets: > > >>> lisA=[1,2,5,9] > >>> lisB=[9,5,0] > >>> lisC=[9,5,0,1] > >>> def intersection_has_two(sequence1, sequence2): > set1, set2 = set(sequence1), set(sequence2) > return len(set1.intersection(set2)) == 2 > > >>> intersection_has_two(lisA, lisB) > True > >>> intersection_has_two(lisA, lisC) > False > > Sets make stuff easy. (I have got to remember that :-) The only reason > to make that a function is the one liner gets a bit long for my taste: > > >>> len(set(lisA).intersection(set(lisB))) == 2 > True > >>> > > Best, > > Brian vdB it does not work. >>> len(set(lisA).intersection(set(lisB))) == 2 Traceback (most recent call last): File "", line 1, in ? NameError: name 'set' is not defined -- http://mail.python.org/mailman/listinfo/python-list
Re: compare list
On 11/15/05, Simon Brunning <[EMAIL PROTECTED]> wrote: > On 15/11/05, Shi Mu <[EMAIL PROTECTED]> wrote: > > it does not work. > > >>> len(set(lisA).intersection(set(lisB))) == 2 > > Traceback (most recent call last): > > File "", line 1, in ? > > NameError: name 'set' is not defined > > 'set' is introduced as a built-in at Python 2.4. If you have 2.3, > there's an analogous module. > > -- > Cheers, > Simon B, > [EMAIL PROTECTED], > http://www.brunningonline.net/simon/blog/ > Yes, i am using python 2.3, I have used from sets import * but still report the same error: > > Traceback (most recent call last): > > File "", line 1, in ? > > NameError: name 'set' is not defined -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter's coordinates setting
On 11/17/05, Steve Juranich <[EMAIL PROTECTED]> wrote: > On 11/17/05, Ben Bush <[EMAIL PROTECTED]> wrote: > > Tkinter's coordinates setting are: the left upper corner is the smallest X > > and Y, which is different from our usual think that Y is largest in that > > location. If i draw some lines on the canvas and show some relationship > > among them, do I need transfer the coordinates? > > Transfer the coordinates of what? > > When you go from the standard right-handed system to the system used > in computer graphics, you use these simple formulas: > > max_x, max_y = image size > screen_x = original_x > screen_y = max_y - original_y - 1 > > HTH > -- > Steve Juranich why subtract 1 from max_y - original_y? -- http://mail.python.org/mailman/listinfo/python-list
Re: about try and exception
On 11/17/05, Carl J. Van Arsdall <[EMAIL PROTECTED]> wrote: > I would think that when the exception occurs the interpreter exits the > block of code it is currently in and enters the exception block. > > Thus the line n = 1/2 would never get executed. > > > -Carl > > Ben Bush wrote: > > I wrote the following code to test the use of "try...exception", > > and I want n to be printed out. However, the following code's output is: > > Traceback (most recent call last): > > File > > "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", > > line 310, in RunScript > > exec codeObject in __main__.__dict__ > > File "C:\py\use\tryExVa.py", line 7, in ? > > print n > > NameError: name 'n' is not defined > > > > the code is here: > > > > try: > > m=2/0 > > n=1/2 > > except ZeroDivisionError: > > pass > > print "Yes!!! This line will always print" > > print n > It is true. If I want to run the statement after the division error such as n=1/2, what should I do? -- http://mail.python.org/mailman/listinfo/python-list
Re: about try and exception
On 11/17/05, Carl J. Van Arsdall <[EMAIL PROTECTED]> wrote: > Shi Mu wrote: > > On 11/17/05, Carl J. Van Arsdall <[EMAIL PROTECTED]> wrote: > > > >> I would think that when the exception occurs the interpreter exits the > >> block of code it is currently in and enters the exception block. > >> > >> Thus the line n = 1/2 would never get executed. > >> > >> > >> -Carl > >> > >> Ben Bush wrote: > >> > >>> I wrote the following code to test the use of "try...exception", > >>> and I want n to be printed out. However, the following code's output is: > >>> Traceback (most recent call last): > >>> File > >>> "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", > >>> line 310, in RunScript > >>> exec codeObject in __main__.__dict__ > >>> File "C:\py\use\tryExVa.py", line 7, in ? > >>> print n > >>> NameError: name 'n' is not defined > >>> > >>> the code is here: > >>> > >>> try: > >>> m=2/0 > >>> n=1/2 > >>> except ZeroDivisionError: > >>> pass > >>> print "Yes!!! This line will always print" > >>> print n > >>> > > It is true. If I want to run the statement after the division error > > such as n=1/2, what should I do? > > > > move the n =1/2 after the division error. > > Basically what will happen in an exception block is once an exception is > thrown the interpreter will leave the block and handle the exception. > Statements following the statement that caused the exception will then > be ignored. > > So if you want n=1/2 to be executed regardless of what happens during > the line m = 2/0 move it outside the block > > Ex: > > > try: > m=2/0 > except ZeroDivisionError: > pass > n=1/2 > print "Yes!!! This line will always print" > print n > > > or likewise you could experiment with: > > > try: > n = 1/2 > m = 2/0 > except: > pass > print 'Yay' > print n > > > Here the line "n = 1/2" will get executed BEFORE the exception is thrown. > > Hope that helps a bit. > > -carl If we do not know when the error will happen during the calculation but still want to continue till end, what should I do? for example: def test(a,b,c): return a/(b-c) q=[1,1,2,2,4,6,9,0] for i in range(len(q)): print test(q[i],q[i+1],q[i+2]) the output is: -1 Traceback (most recent call last): File "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\tt\try2005.py", line 19, in ? print test(q[i],q[i+1],q[i+2]) File "C:\tt\try2005.py", line 16, in test return a/(b-c) ZeroDivisionError: integer division or modulo by zero -- http://mail.python.org/mailman/listinfo/python-list
about dictionary
I have have the following code: >>> a=[3,5,8,0] >>> b={} >>> How I can i assign each item in a as the key in the dictionary b simultaneously? that is, b={3:[],5:[],8:[],0:[]} Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: about dictionary
On 20 Nov 2005 02:59:30 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > b = dict([(x,dict()) for x in a]) > Shi Mu wrote: > > I have have the following code: > > >>> a=[3,5,8,0] > > >>> b={} > > >>> > > How I can i assign each item in a as the key in the dictionary b > > simultaneously? > > that is, > > b={3:[],5:[],8:[],0:[]} > > Thanks! Thanks!!! -- http://mail.python.org/mailman/listinfo/python-list
about polygon
Why I got a black polygon in the following code? How can I make it no-color filled? Thanks! import Tkinter c = Tkinter.Canvas(width=220, height=220) c.pack() c.create_polygon(60,60,100,60,100,100,60,120) c.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: about dictionary
On 11/20/05, Peter Otten <[EMAIL PROTECTED]> wrote: > przemek drochomirecki wrote: > > > Uzytkownik "Shi Mu" <[EMAIL PROTECTED]> napisal w wiadomosci > > news:[EMAIL PROTECTED] > > I have have the following code: > >>>> a=[3,5,8,0] > >>>> b={} > >>>> > > How I can i assign each item in a as the key in the dictionary b > > simultaneously? > > that is, > > b={3:[],5:[],8:[],0:[]} > > Thanks! > > > > > > Other solution: > > b.fromkeys(a,[]) > > Be warned that all keys share the same value. > > >>> a = [3, 5, 8, 0] > >>> b = dict.fromkeys(a, []) > >>> b[3].append(42) > >>> b > {8: [42], 0: [42], 3: [42], 5: [42]} > > Probably not what you want... > > Peter how to do with it? -- http://mail.python.org/mailman/listinfo/python-list
Re: about polygon
On 11/20/05, Jan Voges <[EMAIL PROTECTED]> wrote: > Hi! > > Am Sun, 20 Nov 2005 03:55:21 -0800 schrieb Shi Mu: > > > Why I got a black polygon in the following code? > > How can I make it no-color filled? > > Use create_line instead: > c.create_line(60,60,100,60,100,100,60,120,60,60) > > Jan If so, what is the difference between create_line and create_polygon? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: about dictionary
On 11/20/05, przemek drochomirecki <[EMAIL PROTECTED]> wrote: > > Uzytkownik "Peter Otten" <[EMAIL PROTECTED]> napisal w wiadomosci > news:[EMAIL PROTECTED] > > Shi Mu wrote: > > > > > how to do with it? > > > > Use Ben Finney's, not Przemek's approach if the values are mutables that > you > > plan to modify. If that's what you are asking. > > > > Peter > > Maybe he just want to use dictionary as a set. > He can use SET container instead. > > Przemek How to use SET? -- http://mail.python.org/mailman/listinfo/python-list
about sort and dictionary
Got confused by the following code: >>> a [6, 3, 1] >>> b [4, 3, 1] >>> c {1: [[6, 3, 1], [4, 3, 1]], 2: [[6, 3, 1]]} >>> c[2].append(b.sort()) >>> c {1: [[6, 3, 1], [1, 3, 4]], 2: [[6, 3, 1], None]} #why c can not append the sorted b?? >>> b.sort() >>> b [1, 3, 4] -- http://mail.python.org/mailman/listinfo/python-list
about lambda
what does the following code mean? It is said to be used in the calculation of the overlaid area size between two polygons. map(lambda x:b.setdefault(x,[]),a) Thanks! -- http://mail.python.org/mailman/listinfo/python-list
about dictionary
d is a dictionary. >>> d {0: [[0, 1], [0, 2]], 1: [[0, 1], [1, 2], [1, 3]], 2: [[0, 2], [1, 2], [2, 3]], 3: [[1, 3], [2, 3]]} for the value under each key, if the possible connection is in the dictionary, for example, under key 0. 1 and 2 were found to have a pair in some other places so get [0,1,2] hence, how to design a dictionary, let dicTry= {0: [[0, 1,2], 2: [[0, 1, 2], [1, 2,3]], 2: [[0, 1,2], [1, 2,3], 3: [1,2,3]} Thanks a lot! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to draw a dash line in the Tkinter?
On 11/20/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Ben Bush wrote: > > > How to draw a dash line in the Tkinter? > > use the dash option. e.g. > >canvas.create_line(xy, fill="red", dash=(2, 4)) >canvas.create_line(xy, fill="red", dash=(6, 5, 2, 4)) > > (the tuple contains a number of line lengths; lengths at odd positions > are drawn, lengths at even positions are gaps. note that not all com- > binations are supported on all platforms; if Tkinter cannot find an exact > match, it will pick a the "closest possible"). > > where can I find the option settings for dash line? -- http://mail.python.org/mailman/listinfo/python-list
about list
How to run a function to make [1,2,4] become [[1,2],1,4],[2,4]]? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
global definition
I have a code here. I understand i can not draw lines without the global definition of lastX and lastY. But still confused by its use. when should we use global definition? from Tkinter import * root = Tk() c = Canvas(root, bg='#0e2e0e', height=500, width=1000) frame = c lastX="" lastY="" def click(event): global lastX, lastY if lastX != "": c.create_line(lastX,lastY,event.x,event.y,fill="white") lastX = event.x lastY = event.y c.bind('<1>',click) c.pack() root.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
duplicate items in a list
I used the following method to remove duplicate items in a list and got confused by the error. >>> a [[1, 2], [1, 2], [2, 3]] >>> noDups=[ u for u in a if u not in locals()['_[1]'] ] Traceback (most recent call last): File "", line 1, in ? TypeError: iterable argument required -- http://mail.python.org/mailman/listinfo/python-list
sort the list
I have a list like [[1,4],[3,9],[2,5],[3,2]]. How can I sort the list based on the second value in the item? That is, I want the list to be: [[3,2],[1,4],[2,5],[3,9]] -- http://mail.python.org/mailman/listinfo/python-list
Re: sort the list
On 11/21/05, Daniel Schüle <[EMAIL PROTECTED]> wrote: > Shi Mu wrote: > > I have a list like [[1,4],[3,9],[2,5],[3,2]]. How can I sort the list > > based on the second value in the item? > > That is, > > I want the list to be: > > [[3,2],[1,4],[2,5],[3,9]] > > > >>> lst = [[1,4],[3,9],[2,5],[3,2]] > >>> lst > [[1, 4], [3, 9], [2, 5], [3, 2]] > >>> > >>> > >>> lst.sort(cmp = lambda x,y: cmp(x[1], y[1])) > >>> lst > [[3, 2], [1, 4], [2, 5], [3, 9]] > >>> > > works for Python 2.4 > in earlier Pythons just let cmp = .. away > > Regards, Daniel what does let cmp = .. away mean? -- http://mail.python.org/mailman/listinfo/python-list
keys in dictionary
I run the following code and got wrong message, but I still want to make [1,2],[4,3] and [6,9] to be keys of the dictionary or change the style a little bit. How to do that? Thanks! >>> p=[[1,2],[4,3],[6,9]] >>> n=dict([(x,[]) for x in p]) Traceback (most recent call last): File "", line 1, in ? TypeError: list objects are unhashable >>> -- http://mail.python.org/mailman/listinfo/python-list
sort in the list
I use Python 2.3 to run the following code: >>> a=[[1,2],[4,8],[0,3]] >>> a.sort() >>> a [[0, 3], [1, 2], [4, 8]] >>> I wonder whether the sort function automatically consider the first element in the list of list as the sorting criteria or it just happens to be? Thanks! -- http://mail.python.org/mailman/listinfo/python-list