4,305 Posted Topics
Re: Once again: A Python package is a reference to the name of the folder containing a number of files. A library is the reference to a specific file, can be a .py file. For instance in Python2 you use: import Tkinter this uses file Tkinter.py somewhere in your Lib folder. … | |
![]() | Re: This example may give you a hint on how to proceed: [url]http://www.daniweb.com/software-development/python/threads/191210/1579294#post1579294[/url] ![]() |
Re: You really want to open the file 100000 times in the loop? You need to close the open file it before you save to it. | |
Re: Tinker Bell The little pixie's adventures bring a smile to my face. | |
Re: Take the bytes in an image file and encode it to printable character combinations with base64. | |
Re: On first look you committed a major crime here, you mixed spaces and tabs for indentation. A good way to ruin any Python program. | |
Re: Forgetting to assign the function call's return to a variable is a common mistake for beginners. As Snippsat pointed out, the variable 'a' within the function is local and stays there. Keep plugging along. Just to reiterate, your code should have been ... [code]def something(): a = raw_input('>> ') return … | |
![]() | Re: In the past there have been several projects to write an Operating System in Python. The one that survived seems to be cleese: [url]http://code.google.com/p/cleese/[/url] Remember that Python is a glue language and can easily use ABC or C to do the low level stuff. To write a modern OS would … |
Re: I am still not quite sure what you want, but it looks like you have the right idea with nested loops. This might give you a hint how to proceed ... [code]q = [1, 3, -6, 0] qq = [] for ix, x in enumerate(q): for iy, y in enumerate(q): … | |
Re: You already have the Windows binary self-installer, so it should work right out of the box. Simply run one of the example programs from DaniWeb: [url]http://www.daniweb.com/software-development/python/threads/191210/1525722#post1525722[/url] or something that came with the installation, like: C:\Python27\Lib\site-packages\PyQt4\examples\demos\textedit\textedit.pyw The qscintilla2.dll is also already installed. Download your Eric4 (Eric5 if you have Python32) zipped … | |
Re: You can concatenate the two words into a search word and use module re to help you. Something along this line ... [code]import re text = "The pleasant peasantry likes to eat pheasant!" find = 'as' + 'ant' for word in text.split(): found = re.search(find, word) if found: print("found '%s' … | |
![]() | Re: We really need the whole code. Or at least try to replace RootFinder.root1lbl.configure(text=root1) with self.root1lbl.configure(text=root1) |
Re: [code]from keyword import kwlist for kw in kwlist: print kw [/code] | |
Re: A Python package is a reference to the name of the folder containing a number of files. A library is the reference to a specific file, can be a .py file. For instance in Python2 you use: [B]import Tkinter[/B] this uses file Tkinter.py somewhere in your Lib folder. Module names … | |
Re: Somehow you have to wait for the external program to finish, before you can read the output. | |
Re: If you compare Python code with C# code you find out that C# required ten times more typing than Python. It might be better to ask this question in the C# forum where people love to type. | |
Re: A dictionary coordinate tuple still has the row column problem. There is a code snippet about that here on DaniWeb. | |
Re: At least instructors are giving out nice homework problems. So, what is your exact problem with your homework? | |
Re: You also should consider the possibility that the integer number might be negative. Please leave that to the person that should do his/her own homework. | |
Re: Not sure where you found that awful coding style. I would recommend the following style ... [code]# explore QFrame() from PySide.QtCore import * from PySide.QtGui import * class FrameTester(QWidget): def __init__(self, title, width, height, parent=None): # create the window (this will be instance self) QWidget.__init__(self, parent) # setGeometry(x_pos, y_pos, width, … | |
Re: For some odd reason I remember seeing this very same question somewhere ... [code]# if the error happens in the outer int() function, # then the input() value is lost # recover it from error message e # Python3 syntax try: x = int(input("Enter a number: ")) except ValueError as … | |
Re: Jython has potential, but there are precious few example codes out there. Well, see: [url]http://www.daniweb.com/software-development/python/threads/191210/1565073#post1565073[/url] A lot of my Python26 code runs on Jython just fine. Not the Tkinter code, since Jython uses the Java GUI toolkit instead. Here is an example [code]""" jy_input_output1.py a Jython example for getting input … | |
Re: Maybe Windows is simply too unsafe for Go. Actually the syntax looks a lot like a mix of Object Pascal and C++, not sure where the beauty of Python went. | |
Hello, I am vegaseat, the goofy moderator from the Python forum of DaniWeb. I wanted to know if anyone in the Java forum has played around with Java based Python, also known as Jython. Jython uses easy to learn Python syntax and can use the Java libraries. To make a … | |
Re: Ideal for folks who can't make up their mind which dessert to eat. Such an easy recipe! | |
Re: Sometimes surviving a disaster is worse than dying from it. | |
Re: woooee is on to something, in your case you need to close the file before you can read it ... [code]text = "aim low and reach it" fname = "test7.txt" with open(fname, 'w') as foutp, open(fname, 'r') as finp: # write text to file foutp.write(text) # need to close the … | |
Re: Also class Complex needs a : Please make your indentations uniform with 4 spaces being the most common way. Any good Python IDE will do that for you. | |
Re: I trust this will be cross-platform to keep up with the spirit of Python. | |
Re: At the uni a weeks worth of assembly coding was stored in a shoebox full of punch cards. Don't drop those walking to the reader and get them out of order! ![]() | |
Re: Hint ... [code]# binary for denary 9 bn = '1001' dn = int(bn, 2) print(dn) # 9 [/code] | |
Re: Nice article! I heard that a Canadian is an American without the gun. | |
Re: Thanks for letting us know. So your final code is something like this ... [code]# invert a black&white bitmap file image from PIL import Image filename = "old.bmp" image = Image.open(filename) pixels = list(image.getdata()) # process the pixels (invert) new_pixels = [255-pixel for pixel in pixels] image.putdata(new_pixels) image.save('new.bmp') [/code] | |
Re: If you want integer keys, try this ... [code]# dictionary comprehension needs Python27 or higher text = """\ 1\thello 2\ttest """ fname = "mytest.txt" with open(fname, "w") as fout: fout.write(text) with open(fname, "r") as fin: d = {int(x.strip().split('\t')[0]):x.strip().split('\t')[1] for x in fin} print(d) # {1: 'hello', 2: 'test'} [/code] | |
Re: This short code might just give you a hint: [url]http://www.daniweb.com/software-development/python/threads/191210/1558321#post1558321[/url] | |
Re: These two code examples will illustrate the purpose and meaning of [B]Popen[/B] ... [code]# save this code as calendar_may_2011.py import calendar calendar.prmonth(2011, 5) [/code]... now run this code ... [code]# calendar_may_2011_popen.py # Popen (Pipe open) will open the 'pipe' containing the # standard output stream from a given Python program … | |
I would say Disney World. I always have a good time there. However, a "cow tipping" excursion into Wisconsin sounds like fun too! | |
Re: Here is a simple example ... [code]# pqt_TextEdit2.py # clear PyQT's QTextEdit multiline text entry box from PyQt4.QtCore import * from PyQt4.QtGui import * class MyFrame(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) # setGeometry(x_pos, y_pos, width, height) self.setGeometry(100, 50, 300, 180) self.setWindowTitle('QTextEdit() clear') self.edit = QTextEdit(self) self.edit.append('Just some text.') self.edit.append('You can … | |
Re: Another simple example ... [code]# convert to a dictionary and handle key collisions a = [ ('a', 1), ('b', 5), ('c', 7), ('a', 2), ('a', 3) ] d = {} [d.setdefault(k, []).append(v) for k, v in a] print(d) # {'a': [1, 2, 3], 'c': [7], 'b': [5]} [/code] | |
Re: Please use code tags with your code to preserve the indentations. Otherwise the code is very difficult to read and not too many folks will help. [noparse][code][/noparse] your properly indented Python code here [noparse][/code][/noparse] | |
Re: [code]try: x = int(input()) except ValueError as err: print(err) # split at ':', strip white space then "'" err2 = str(err).split(':')[1].strip().strip("'") print(err2) ''' possible result (Python3) ... invalid literal for int() with base 10: 'abcd' abcd ''' [/code] | |
Re: You might want to update to the latest version of Jython. This one works just fine on my Windows7 machine ... [code]"""jy_hello_bat.py run a batch file using Jython The Windows batch file 'hello.bat' is: echo Hello, from batch file tested with jython2.5.2 """ import subprocess subprocess.call('hello.bat') [/code]In my experience most … | |
Re: You need to keep your indentation spacing consistent. Like predator78 pointed out, you are switching from 4 spaces to 3 spaces in the same block of code. Not good! Most Python IDEs will assist you on obvious mistakes like that. | |
Re: Take a quick look at: [url]http://www.daniweb.com/software-development/python/threads/20774/1537012#post1537012[/url] or an older version: [url]http://www.daniweb.com/software-development/python/code/216639[/url] Then follow tony's advice on sorting. | |
Re: Please use code tags with your code to preserve the indentations. Otherwise the code is very difficult to read and not too many folks will help. [noparse][code][/noparse] your Python code here [noparse][/code][/noparse] Also, most programmers use 4 spaces (no tabs) as indentation. Many of the Python IDEs will do that … | |
Re: It's just like any other addiction! Spread your addictions out a little. ![]() | |
Re: Works fine for me using Python27 on Windows7 OS. | |
Re: Some other options ... [code]with open("testfile4.txt","w") as myfile: for line in ("line 1", "line 2", "line 3"): # python2 print >>myfile, line # python3 #print(line, file=myfile) with open("testfile4.txt") as myfile: print(myfile.read()) ''' line 1 line 2 line 3 ''' [/code] |
The End.