4,305 Posted Topics
Re: To further your learning experience take a look at: [url]http://www.daniweb.com/techtalkforums/post257347-78.html[/url] I think this is related to something you are working on. | |
Re: Here are the basics of commandline arguments ... [code]# commandline arguments import sys print sys.argv[0] # prints the filename of your script print sys.argv[1] # the first parameter print sys.argv[2] # the second parameter #or print sys.argv[1:] # all parameters [/code]sys.arg[1] and higher is only present if you give enough … | |
Re: Here is a small project, go through all the functions listed at: [url]http://www.phim.unibe.ch/comp_doc/c_manual/C/FUNCTIONS/funcref.htm[/url] and come up with a code sample of a practical application for each function. | |
Re: I am a little confused, hope this will help ... [php]# create a row of colorful buttons and assign some action to each from Tkinter import * def action1(): label1.config(text='You pressed button1') def action2(): label1.config(text='You pressed button2') def rng(): label1.config(text='Now you could be running an RNG!') form1 = Tk() form1.title('Press … | |
Re: The Python module glob will get you there ... [code]# get all the file types in a given directory: import os, glob # change to the desired directory os.chdir("C:/Documents and Settings/Matt/Desktop") # get all the files in that directory into a list file_list = glob.glob("*.*") # show the list print … | |
Re: Function line.replace(" ","\t") works very well, but it may depend on how many spaces your tab is set at in your editor, as you look at the result. You could use double tabs like line.replace(" ","\t\t"). To add a commandline argument, change this part of the code ... [code]# read … | |
Re: Since you initially allow duplicates and then want to change them you should use a list. A set would automatically eliminate a duplicate element, not what you want. See, if you can use something like this ... [php]# go through each item in a list of strings and make each … | |
Re: To get a hang of the basics of Python, I would recommend the book "Learning Python" by Mark Lutz and David Ascher, published by O'Reilly (no relation to the buffoon on TV!) | |
Re: Ouch! This is not an easy project for a newbie! I corrected some things in your code to make it work at least ... [code]from Tkinter import * def press_a(event): # you are mixing console and GUI #print 'You Pressed a' # try this ... root.title('You Pressed a') def press_b(event): … | |
Re: How many software engineers does it take to change a light bulb? | |
Re: Something like this might work for you ... [php]# load and display several images using Tkinter # Tkinter reads only GIF and PGM/PPM images # (for additional formats use Image, ImageTk from PIL) from Tkinter import * root = Tk() root.title("Click me!") def next_image(event): """toggle between image2 and image3""" global … | |
Re: This is going to be tough, because "print a" gives you a string consisting of two hex values --> '\xc4\x93'. The function ord() seems to only handle single characters. This works ... [code]>>> b = unichr(275) >>> b u'\u0113' >>> ord(b) 275 [/code] Is there a way to decode('utf8')? Sorry, … | |
Re: Removing a directory, all subdirectories and files seems to be a consequential operation, and I would error prove it to the hilt. | |
Re: If with .doc file you mean a MS Word file, no way! Just look at a typical Word .doc file with an editor and you will know why. | |
Re: You have to reference dalabel via DisFrame --> frame --> Panel1, so it ends up frame.Panel1.dalabel.SetLabel(str(time.time())) | |
Re: Excerpt from a heated discussion a while back: [QUOTE]... or Django, or Turbogears, which provide a Ruby-on-Rails like framework to construct your web-app on. Turbogears uses CherryPy, incidentally, but also adds in a templating system (Kid) and a database persistance layer (SQLObject). Django does something similar, and also provides an … | |
Re: Thanks for sharing this insight! [QUOTE]eval(str) Evaluate a string and return an object[/QUOTE] | |
Re: Python to the rescue ... [code]def test1(): """In this documentation string the indentation becomes part of the string""" pass print test1.__doc__ print def test2(): """ This is why Python relaxes the indentation rules within a multiline string to allow this kind of documentation string """ pass print test2.__doc__ [/code] | |
Re: Just a few quick questions: What operating system are you running? What version of Python do you have installed? Are you saving your Python files as .py files? Do you use an IDE, which one? | |
Re: You are very close, very nice list compare by the way! Avoid anything within the while loop that slows things down, like print statements. You also don't need any list sorting. Here would be my suggestion ... [code]import random def computer_random(): """Let computer create a list of 6 unique random … | |
Re: Simply add the outer while loop to exit only on option zero: [code]import os selection = 1 while selection != 0: while True: print print "PROGRAM MENU" print "1 - open xmms" print "2 - open emacs" print "3 - open gparted" print "4 - open gedit" print "5 - … | |
Re: Nice idea! Do you want to do more? Take a close look at the US flag, it's a bit more complicated. [url]http://www.crwflags.com/fotw/flags/us.html[/url] | |
Re: Looks like you are getting familiar with formatted strings and string input, great! Could be quite funny depending on what you put in! | |
Re: Listen to Dave's advice, he netted them all! Let int main() return something like a zero, rather than an empty plate. Sounds like my kind of menu. What's for DESSERT? | |
Re: See my comments in the code ... [code]from Tkinter import * def calculate(): try: metre = float(enter1.get()) result = metre * 100 #label2 = Label(calculate, bg="blue") # error here label2 = Label(root, bg="blue") # black text on blue is hard to see! label2.grid(row=3, column=0) # this was missing label2.config(text=str(metre)+ 'meters … | |
Re: Note that transient() is not a built-in method of Python. Which module are you importing? | |
Re: IDLE is simply an environment you write your Python programs in. It is basically a text editor you can run your code from. You can do simple graphics with Tkinter that is already part of the Python distribution. For more advanced graphics download PIL. It among other things expands Tkinter's … | |
Re: Maybe this will help you ... [code]import time print time.ctime() # Sat Sep 02 18:23:53 2006 # get just hr, min, sec of present time tuple hr, min, sec = time.localtime()[3:6] print hr, min, sec # 18 23 53 print sec, type(sec) # 53 <type 'int'> # if you just … | |
Re: To get happy it's Southern Comfort straight up! To quench the thirst it's red California table wine like a decent Cabernet Sauvignon with about 1/3 orange juice all ice cold! When gambling I like to keep my wits and drink hot chocolate. | |
Re: Smart observation a1eio! Using Python's builtin function names for a variable name seems to trip plenty of new programmers. I got tripped on str when I started writing Python code. Module names can also trip you up! Use the following to check for names you want to avoid ... [code]help("__builtin__") … | |
Re: A closure is a block of code that can be passed as an argument to a function call. In languages like Lisp and Ruby closures are easily implemented. In Python you can do it, but it is a bit more code. Lambda is often used for that. Here would be … | |
Re: [QUOTE=Dave Sinkula][FONT=Courier New]itoa[/FONT] is nonstandard; [FONT=Courier New]sprintf[/FONT] is standard. [FONT=Courier New]#include <iostream.h>[/FONT] is nonstandard; [FONT=Courier New]#include <iostream>[/FONT] is standard.[/QUOTE] Dave is correct here, itoa() is not ANSI-C, but supported by most compilers. | |
Re: Matt, as I look at your initial GUI code I can see two problems not related to Tkinter. I marked them with # !!!!!!!!!!!!!!!!, those will be errors! [php]from Tkinter import * def addMen(): addMenC = input("Where do you wish to add men? (country 1,2,3 or 4):") addMenLoop = True … | |
Re: You can use the command shell: [code]# with windows import os os.system("CLS") [/code] or [code]# with linux import os os.system('clear') [/code] or [code] # if you don't mind that the cursor is at the bottom print '\n' * 25 [/code] Actually, the best way is to design your program so … | |
The code portion of one of my snippets does not always show. [url]http://www.daniweb.com/code/snippet451.html[/url] It's there when I check with edit. I resubmit and it's there for the moment only. Need help! ![]() | |
Re: On the road again ... Found this example on my notebook computer: [code=python]import wx class MyFrame(wx.Frame): """frame with panel containing two labels and two textcontrols""" def __init__(self): wx.Frame.__init__(self, None, -1, 'wx.FlexGridSizer', size=(350, 100)) panel = wx.Panel(self, -1) basicLabel = wx.StaticText(panel, -1, "Basic wx.TextCtrl:") # size height = -1 implies height … | |
| |
Re: I recommend Visual C# .Net. You can pick up the whole package for less than $100 (amazon.com). You need Windows on your computer, preferably XP and a good amount of free disk space. It is easy to bring in graphics, color and sound through the various components in the builder. … | |
Re: Looks like a nice program. On my computer (OS = Windows XP) the last tkMessageBox.showinfo() prevents any focus on entry1, no cursor! Strange indeed! | |
Re: The tuple and the list have a few things in common. They are both indexed containers for objects. The tuple is a very simple container to put some objects together, separated by commas, so you can send them to and from functions or stick them into lists as a group … | |
| |
Re: How familiar are you with Python? I noticed in your code that the statement after "if key in index:", or the statements in the function "def get_accession_num(fasta_record):" are not properly indented to form a block. Also where does index come from? Can you show us a short sample of your … | |
Re: What is your present solution, even if brute force? | |
Re: The functions are contained in module os. Function os.path.getmtime() gives you the last modified time in seconds since the beginning of 1/1/1970 (epoch). You have to do some formatting with module time functions to make it readable for the ordinary mortal. The size of the file is returned by os.path.getsize() … | |
Re: A while back I wrote a little snippet about turtle graphics, just to introduce people to the fact that it exists within Tkinter. It simply draws a bunch of shifted squares that could form some kind of graphical art. Take a look at it and experiment with your own design: … | |
In case you are curious, I just posted a new tutorial "Python and Multimedia, Part 1, The amazing Webbrowser Module" on DaniWeb at: [url]http://www.daniweb.com/tutorials/tutorial47392.html[/url] I would love some input from our Linux and Unix friends to see how much cross platform the module is. Post any comments in this thread! | |
Re: Here is a typical example of a wx.Menu() ... [code=python]# a wxPython Frame with menu, statusbar and about dialog import wx import os # give the ids a unique integer value ID_ABOUT = 101 ID_OPEN = 102 ID_EXIT = 103 class MyFrame(wx.Frame): """frame with menu, statusbar and about dialog, inherits … | |
The DaniWeb community is pretty worldly, so I though it would be interesting to post the price of beer in your local pub. Be somewhat informative: Here in the state of Nevada I like to go to Barley's Casino and Brewing Company. A pitcher (60 ounces) of Red Rock lager … | |
Re: Take a look at the wxButton demo at: [url]http://www.daniweb.com/code/snippet502.html[/url] You might have to modify the events slightly. wx.EVT_BUTTON is basically a single left mouse click. wx.EVT_LEFT_DCLICK is your left double click. |
The End.