1,175 Posted Topics
Re: Read the docs of Python3: [url]http://docs.python.org/3.1/whatsnew/3.0.html?highlight=callable[/url] [QUOTE]Removed callable(). Instead of callable(f) you can use hasattr(f, '__call__'). The operator.isCallable() function is also gone.[/QUOTE] You can run this program to check what you have available: [code=python]# print all builtin functions/methods # do a case insensitive sort then print ... print( '\n'.join(sorted(dir(__builtins__), key=str.lower)) … | |
Re: Here is an example using the module pygame: [code=python]# experiments with module pygame # free from: http://www.pygame.org/ # load, display and move an image import pygame as pg # initialize pygame pg.init() # pick an image you have (.bmp .jpg .png .gif) # if the image file is not in … | |
Re: Market capitalism is sustainable. Everybody getting rich is not! | |
![]() | Re: If Sound Recorder has a command-line option, then you can send the arguments along to start it etc. |
Does anyone know a good internet site where I can 'park' my Python code? Easy download, upload, and search. | |
Re: You need to use one of the GUI toolkits for the 2 frames to respond to each other. | |
Re: Salem has a very good point, it would be very confusing to the user to show ***** that does not match the password string in length. | |
Re: Your carlist is a list of instances of the class carType. To compare the car's name you have to use the instance.name as shown here: [code=python]class carType: def __init__(self, name, brand, price): self.name = name self.brand = brand self.price = price carlist = [ carType("Viper", "Dodge", 80000), carType("Mustang", "Ford", 25000), … | |
Re: List values are accessed by their index. Dictionary values are accessed by their key. To allow for high speed key searches, the keys are in a hash order. So a dictionary sorted alphabetically by it's keys would make no sense and would defeat the whole dictionary idea. The best you … | |
Re: Here is a Python output with an image: [code=python]# draw a flower with module turtle import turtle as tu tu.title('I call this one Flower') # values for speed are 'fastest' (no delay), 'fast', (delay 5ms), # 'normal' (delay 10ms), 'slow' (delay 15ms), and 'slowest' (delay 20ms) tu.speed('fastest') #turtle.color((.3,.5,.3)) tu.color('red') tu.width(2) … | |
Re: You can use Hide() and Show() as explained here: [code=python]# create two frames with wxFrame, only one is showing import wx class Frame1(wx.Frame): def __init__(self, parent, mytitle): wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle) self.SetBackgroundColour("green") # pass frame1 to frame2 as instance self self.frame2 = Frame2(None, 'Frame1', self) # create input widgets self.button1 … | |
Re: I would use module subprocess: [code=python]# os.system() does not allow the Python program # to run in the background, whereas subprocess does import subprocess # remove "arg1", "arg2" if you don't have any command line args subprocess.call(["C:/Python25/Python.exe", "Skripta.py", "arg1", "arg2"]) [/code] | |
![]() | Re: Look through your code and test print some of your variables to see what is going on. Create a word list then something like this will work: [code]s = 'he said why' word_list = s.split() n = 0 for word in word_list: if word[0] == 'w': print word_list[n] n += … |
Re: Looks like they want you to flatten the list. | |
Re: Like snippsat so wisely said, [B]"do not change a list that your are iterating over"[/B] this will upset the indexing of the list during the iteration process. snippsat also recommended to iterate over a copy of mylist: [code=python]mylist = ['bunnies', 'apples', 'animals', 'fruit', 'amsterdam'] mylist_copy = list(mylist) # or mylist[:] … | |
Re: This would give you the sum of digits: [code=python]def sum_digits(n): total = 0 for digit in str(n): total += int(digit) return total [/code]Now expand this function so you multiply int(digit) with each other. Notice that I didn't use 'sum' because sum() is a Python function. | |
Re: Probably one of those many pop up ads, or the ghost of Dani Web. | |
Re: On the other hand 'in' would fetch: 'you love me!' which would be a shame to miss! | |
Ever since I got my Ubuntu notebook computer, I can't fail to notice how fast it starts up (and shuts down) compared to my Windows Vista notebook. Other than the system itself, the virus program seems to take more and more time as it checks for seemingly millions of possible … | |
Re: [QUOTE=joshSCH;805477]... When Ronald Reagan took office, the economy was in an arguably worse state than it is now. However, his strives to limit government, and leave the private sector alone helped us to recover, and enjoy the prosperities of the 90s. Obama plans to do the very opposite... Hmmm.... I … | |
Re: Oh I see, you want the instance name be the name of the person. That will not be a good idea, because identifiers in Python don't allow spaces. A dictionary, where the name is the key and the value is a ( home, mobile, email ) tuple or list will … ![]() | |
Re: I like[B] nutella[/B], a chocolaty hazelnut spread, sort of like a much improved peanut butter. | |
Re: [QUOTE=Himaloy;903106]It does not exist when you think about something very deeply than a image can be born on your mind,and then people see this "GHOST" okay then we can say it exists but only in peoples mind :)[/QUOTE]IMHO, you are right on! If you see too many ghosts, you are … | |
Re: [QUOTE=debasisdas;411140]if you have brain go for it. else other options are open for you.[/QUOTE]I agree, if you have the brain, she/he doesn't need much of it. | |
![]() | Re: Are you using tabs for indents? They are screwed up! I normally don't even bother with code that has obvious signs of tabs. Do not use 'dict' as identifier, it is the name of a Python function. Also, test your list, the punctuation marks are still attached: [code=python]test = "Hello, … ![]() |
Re: On your last post --> Please do not double post, it is rude! | |
Re: Corrected your code a little and it works just fine: [code=python]''' TextFileDisp00.py ''' import wx import codecs #------------------- class TextFrame(wx.Frame): def __init__(self, parent, mytitle, mysize): wx.Frame.__init__(self, parent, -1, mytitle, mysize) self.menubar = wx.MenuBar() self.file = wx.Menu() self.SetMenuBar(self.menubar) self.menubar.Append(self.file,'&File') self.openitem = self.file.Append(wx.ID_ANY,'&Open') self.Bind(wx.EVT_MENU,self.openevent,self.openitem) self.runitem = self.file.Append(wx.ID_ANY,'&Run') self.Bind(wx.EVT_MENU,self.runevent,self.runitem) self.exititem = self.file.Append(wx.ID_ANY,'E&xit') self.Bind(wx.EVT_MENU,self.exitevent,self.exititem) … | |
Re: Since parallel is supposed to be a package, check if there is a file __init__.py in folder C:\\Python26\\Lib\\site-packages\\parallel | |
Re: Variables in Python are officially names/identifiers (keys in a dictionary) of object references. I still like to refer to them with the old fashioned name variables, this way other folks know what we are talking about. | |
![]() | Re: If you use the Windows OS: [code=python]# get the character of a key pressed (no return key needed) # works only in the command window and with Windows OS # msvcrt.dll is the MS C library containing most standard C functions from msvcrt import getch print "press a char key … |
Re: With James Bond the Brits have a leg up 'gainst the Yanks. Also, let's not forget the legendary Benny Hill. However when it comes to wars, the Yanks have beat the Brits by a mile. | |
![]() | Re: Microsoft's msvcrt.dll is a dynamic link library, look here for some of its contents: [url]http://msdn.microsoft.com/en-us/library/ms235446(VS.80).aspx[/url] |
Re: [QUOTE=Salem;899242]The maximum number of open files a process is allowed to have comes from the Operating System. ... [/QUOTE]That is not all of it. In Python you have constructs like: [code=python]for line in file(filename): # do something with line [/code]Here the closing of the file is left to the very … | |
![]() | Re: There are a number of GUI drag and drop builders. Boa Constructor: [url]http://www.daniweb.com/forums/post400296-107.html[/url] wxGlade: [url]http://www.daniweb.com/forums/post400189-106.html[/url] |
Re: Python has a module numpy that will make things easier. However, you can use a Python list of lists for a matrix as shown in this example: [code=python]# create a 2D matrix of zeros and populate it def make_list(size): """create a list of size number of zeros""" mylist = [] … | |
Re: This might help: [code=python]# see also: http://www.daniweb.com/forums/post896314-177.html import math def fuzzyequals(a, b, delta=0.0000000001): """ returns true if a is between b-delta and b+delta used for comparison of floating point numbers a and b """ return abs(a-b) < delta # cosine of 90 degrees should be zero n = math.cos(math.radians(90)) #n … | |
Re: A good part of coding in Python is to know what its modules are doing. The module datetime makes your life a lot simpler, it also flags down impossible dates: [code=python]# convert one date format to another # check the Python manual under strftime() # to get the % format … | |
Re: The function exec() does not know where class Vent is coming from. You could try something like: exec(mystring, globals()) Now you are putzing around with the global dictionary, dangerous territory indeed! | |
Re: Since a list is a mutable object, it would still behave global if it is used as a function parameter/argument. To wit: [code=python]def add_element(mylist2): mylist2.append(33) return mylist2 mylist = [1,2,3,4] mylist3 = add_element(mylist) print(mylist) # [1, 2, 3, 4, 33] oops! print(mylist3) # [1, 2, 3, 4, 33] [/code]To prevent … | |
Re: Why use tabs when you could use 4 spaces like everybody else. | |
![]() | Re: [QUOTE=sravan953;896232]It doesn't work even though I run it in the DOS Console window! It just pops up and then closes....(even when I modified the code with the time module).. In IDLE, when I run it, it says "'module' not found"[/QUOTE]Works well on my Linux/Ubuntu computer. I code with the Geany … |
Re: In order to make added text transparent you have to use the canvas approach. I left a working example here: [url]http://www.daniweb.com/forums/showpost.php?p=895637&postcount=20[/url] | |
Re: Are you using the Python Shell (>>> prompts), or an editor like the IDLE editor? | |
Re: To read in a list of integers with a loop you have to create an empty list and append to it with each input. For instance: [code=python]# create a list of integers # note that input() gives a string in Python3 n_list = [] while True: n = int(input("Enter a … | |
Re: [QUOTE=shoemoodoshaloo;894965]Hey guys, I wrote a file the other day, which reads in data, adds a column, and then reads the data out to a specific file. I thought everything was working great, with all of your help; however, I am now running into another problem. The output data looks like … | |
Re: [QUOTE=jlm699;894108]You could maintain a list of open file handles like this: [code=python] open_files = [] for each_name in names_list: open_files.append(open(each_name + '.bed', 'w')) [/code] Then that list would be full of open file handles.[/QUOTE]A nice feature of this approach is that the index of the file handle in open_files is … | |
Re: If you just want to replace certain extensions, you can use something like this: [code=python]file_list = [ 'list_nonunique1.py', 'Gene_read1.pyw', 'wx_psutil1.pyw', 'pa16names.txt', 'wxFrame_centerthings1.pyw', 'averagewords1.py', 'oneline.txt', 'tk_coinflip.pyw'] # replace extension .pyw with .py new_list= [] for fname in file_list: if '.pyw' in fname: fname = fname[:-3] + 'py' new_list.append(fname) print(fname) """ my … |
The End.