988 Posted Topics
Re: Well, it took George Bush eight years to make such an ungodly mess, so it will take Barack Obama and his team a little while to fix it. The first things you may see is that the torture of prisoners is gone, and the US will treat other countries like … | |
Re: In Python it would look like: [code=python]fout = open("test1.txt", "w") fout.write("save something ...\n") fout.write("save something more ...\n") fout.close() # or C++ style (allowed in Python2) fout = open("test2.txt", "w") print >>fout, "save something ..." print >>fout, "save something more ..." fout.close() # more like PERL import sys old = sys.stdout … | |
Re: I wonder if they ever got all that salmonella contaminated peanut butter off the shelves? | |
Re: I wouldn't walk through a cemetery in the middle of the night! Hollywood loves to scare people with ghost stories/movies. | |
Re: [QUOTE=jwenting;469208]Not all illegal aliens take to criminal enterprise beyond the federal crime of crossing the border illegally maybe, but it is a fact that those who do are often among the worst repeat offenders. And they often get very light sentences, being usually just kicked out of the country only … | |
Re: Brain: An enchanting brain has to be capable of a balanced mix of creativity, wit and understanding. My bosses brain contains the C++ manual in every detail, but otherwise he is rude and crude and devoid of any people skills. He has a very ugly wife and three very ugly … | |
Re: I you are on Windows and have several versions of Python installed, you can write a little batch file to make sure the IDLE of the correct version is runnig: [code]REM a batch file to force IDLE to use Pyhon30 REM saved as IDLE30.bat C:\Python30\pythonw.exe -u C:\Python30\Lib\idlelib\idle.pyw [/code]The poor quality … | |
Re: Your problem is too simple to bother with regex: [code=python]mylist = ['adam', 'bill', 'jon/juan'] newlist = [item.replace('/', '') for item in mylist] print(mylist) # ['adam', 'bill', 'jon/juan'] print(newlist) # ['adam', 'bill', 'jonjuan'] [/code] | |
Re: Maybe something like this: [code=python]import random low = 1 high = 9 mylist = [(random.randint(low, high), ) for k in range(10)] print(mylist) """ a possible display of one element tuples --> [(9,), (5,), (6,), (2,), (8,), (3,), (4,), (2,), (6,), (1,)] """ [/code] | |
Re: Not quite sure what you want, but maybe function zip() will help: [code=python]buy_list = [1,2,3,4,9,11,77,99] sell_list = [0,7,8,10,12,15] # removes the excess items of the longer list buy_sell = zip(buy_list, sell_list) print buy_sell for buy, sell in buy_sell: print buy, sell """ my display --> [(1, 0), (2, 7), (3, … | |
Re: Here is an example: [url]http://www.daniweb.com/forums/showpost.php?p=890166&postcount=111[/url] | |
Re: Python 2.5.4 is the version I have installed. Python 2.6 has all sorts of problems at least on Windows, since it is compiled with a different MS C compiler. A good number of modules are simply not available for Python 2.6. Python 2.6 is supposed to help you to transition … | |
Re: Germany during WW2 send many of their most educated people to the frontline because the ultra rightwing government in charge in those days did not like well educated people. | |
Re: Imagine a planet where all the beings live by unbiased rules and pay their fair taxes. | |
Re: In order to make buttons behave like standard buttons in your dialog box, you simply create an image button from a standard button and an image: [code=python]class BitmapDialog(wx.Dialog): def __init__(self, text): wx.Dialog.__init__(self, None, -1, title="BitmapDialog", size=(250,150)) bmp = wx.Bitmap('ok.png') w, h = bmp.GetSize() x = 35 y = 90 wx.StaticBitmap(self, … | |
Re: Use this to clear the screen on a console program: [code=python]import sys # on Windows os.system("CLS") # on Linux os.system('clear') [/code] Also for my taste avoid using globals, they can get you into conflicts. You can generally pass them to and from functions in the arguments. Do you want to … | |
Re: [QUOTE=ithelp;870585]What are old C/C++ programmers supposed to do then ? :([/QUOTE]Get involved in politics, that takes little brain power. | |
Re: Just to add to shibby's very nice explanation: [code=python]# passing a class variable to other classes class C1(object): def __init__(self): print("in class C1") # self makes mc1 available to the class instance self.mc1 = 77 class C2(object): mc2 = 88 def __init__(self): print("in class C2") # create an instance of … | |
Re: Thanks AD! My dad had an LP of Victor Borge with this sketch on it! Very amusing! | |
Re: The pygame.KEYDOWN event figures this one out, just put it into an if statement. | |
Re: Here is an example without a titlebar and showing fullscreen: [code=python]# wx.Frame with no title bar and showing fullscreen # modified from vegaseat's example import wx def exit(event): frame.Close(True) app = wx.App(0) # create a window, no-parent, -1 is default ID, style with no titlebar frame = wx.Frame(parent=None, id=-1, pos=(50,100), … | |
Re: This line: if float(path_value[i]) == float(line1000[0]): will give you major headaches, since floats are usually off by very small values and are such not always equal. Use the function fuzzy_equals for that: [code=python]def fuzzy_equals(a, b, delta=0.000001): """ used for comparison of floating point numbers a and b """ return -delta … | |
Re: Who says you have to use aluminum to build windmills? The present NiH batteries on hybrid cars do not use cadmium. The safe life span of a nuclear power plant is 25 years and then you are stuck with a highly radioactive mess. If you use aluminum for your windmills, … | |
Re: Just heard in the financial news: The total of bad loans of the Royal Bank of Scotland is equal to the annual revenue of England. That's just one bank. | |
Re: Conservatives are me, me, me and don't give a hoot about their fellow human beings. Libertarians believe in full individual freedom of thought, expression, and action. | |
| |
Re: I don't know who the heck Narue is, just let him stay! | |
I am looking for a good example of the tarfile module, writing to and reading from an archive. Particularly the highly compressed filename.tar.bz2 format. | |
Re: Wonder if you can get past airport security with a suitcase full of antimatter? | |
Re: Starting with and empty string, you have to build up your code string in the loop, and then write it to the file outside the loop: [code=python]def encode(): mess = raw_input ("Enter message:") joinnum = "" for i in mess: nummess = ord (i) * 2 * 7 + 3 … | |
Re: Please do not mix tabs and spaces for indentations in your code. Makes a mess of your code when I copy it into my editor! Many editors have different spaces per tab settings. Use spaces only, preferably 4 spaces like most programmers use! Your problem is here: [code=python] for j … | |
Re: Just an observation, I would avoid using variable names like l1, l2 and so on, they look a lot like numbers 11, 12. Here is an example how to use Python function map(): [code=python]q = [1, 2, 3, 4, 5] # map applies float() to every element in the list … | |
Re: My advice, don't use the Python Shell for programming, use an editor. The Python Shell interative interpreter is only for very short tests. It is basically there to confuse beginners and discourage them from using Python. :) | |
Re: Do you have to maintain the position in the second file? What would a line of data in that file look like? | |
For the second year running Python has been selected as the Language of the Year by Linux users: [code] Linux Users' Programming Languages of the Year 2008 PHP 115 13.36% Perl 72 8.36% Python 226 26.25% Ruby 46 5.34% C 114 13.24% C++ 129 14.98% Java 106 12.31% Lisp 9 … | |
Re: Expanding on jrcagle post: [code=python]import shutil source_file = r"C:\Python25\Atest\Bull\shutil_test.txt" destination = r"C:\Python25\Atest\Bull\Test" # this copies the source file to the destination directory # the destination directory has to exist # if the filename already exists there, it will be overwritten # access time and last modification time will be updated … | |
Re: Oh yes, Python has an array type, but you must import module array: [code=python]# module array has Python's array type import array # Python25 use 'c' as the character typecode # Python30 uses unicode character typecode 'u' char_array = array.array('c', 'hello world') print(char_array[0]) # h print(char_array) # array('c', 'hello world') … | |
Re: HTML code is easy to learn and you can format text using a simplified version of it, and show it in the wx.html.HtmlWindow() widget. Here is an example: [url]http://www.daniweb.com/forums/post803532-107.html[/url] | |
| |
Re: [QUOTE=jrcagle;803601]Just to add to scru's point: Being able to re-use code is an extremely important but sometimes overlooked feature of programming. Its main value is not saving time, but eliminating bugs. That is, if the code for CD works provably correctly (or testably correct even), then a DVD class built … | |
Re: Welcome to this forum. Since just about everything in Python is an object, you are doing OOP already. Look at it this way, a class is just one more convenient tool to group things together. If the class concept bothers you, you can do major programming without it. After all, … | |
Re: > I know Python introspection feature are powerful, what I can't seem to figure out is how to get the name of the current class. > > Example: class Foo: def bar(self): print(classname) > Then my output should be `Foo`. Bonus points if I can get which module it resides … | |
Re: Even the IDLE that comes with Python30 will insist to use PYthon25 if installed. There must be a file association config file somewhere that screws this up. I finally wrote a batch file (I use Windows Vista) and that solves the problem: [code]REM a batch file to force IDLE to … | |
Re: There would be no changes using a list of vowels, the 'in' operator works the same way: [code=python]first = raw_input("Enter a sentence :\n") second = "" #vowels = 'aeiou' vowels = ['a','e','i','o','u'] for i in first: if i in vowels: second = second+i.upper() else : second = second+i print second … |
The End.