4,305 Posted Topics

Member Avatar for mukthyar1255

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. …

Member Avatar for Lardmeister
0
307
Member Avatar for vom53

This example may give you a hint on how to proceed: [url]http://www.daniweb.com/software-development/python/threads/191210/1579294#post1579294[/url]

Member Avatar for vom53
0
135
Member Avatar for bmanzana

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.

Member Avatar for bmanzana
0
118
Member Avatar for epdmcoatings
Member Avatar for sneekula
3
334
Member Avatar for collizz

Take the bytes in an image file and encode it to printable character combinations with base64.

Member Avatar for NormR1
0
241
Member Avatar for Thisisnotanid

On first look you committed a major crime here, you mixed spaces and tabs for indentation. A good way to ruin any Python program.

Member Avatar for Schol-R-LEA
0
333
Member Avatar for LogicallyInsane

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 …

Member Avatar for LogicallyInsane
0
86
Member Avatar for leegeorg07

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 …

Member Avatar for SamarthWiz
0
167
Member Avatar for zpzp16

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): …

Member Avatar for vegaseat
-1
110
Member Avatar for pmennen

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 …

Member Avatar for vegaseat
0
522
Member Avatar for tbjo

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' …

Member Avatar for vegaseat
0
191
Member Avatar for jamie-pu

We really need the whole code. Or at least try to replace RootFinder.root1lbl.configure(text=root1) with self.root1lbl.configure(text=root1)

Member Avatar for TrustyTony
0
170
Member Avatar for mukthyar1255
Member Avatar for TrustyTony
0
149
Member Avatar for mukthyar1255

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 …

Member Avatar for vegaseat
0
98
Member Avatar for markfw

Somehow you have to wait for the external program to finish, before you can read the output.

Member Avatar for markfw
0
347
Member Avatar for Sandmann

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.

Member Avatar for vegaseat
0
169
Member Avatar for Shane the House

A dictionary coordinate tuple still has the row column problem. There is a code snippet about that here on DaniWeb.

Member Avatar for vegaseat
0
121
Member Avatar for sahityaonprakri

At least instructors are giving out nice homework problems. So, what is your exact problem with your homework?

Member Avatar for vegaseat
0
116
Member Avatar for mikio

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.

Member Avatar for vegaseat
0
2K
Member Avatar for markfw

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, …

Member Avatar for vegaseat
0
226
Member Avatar for Ronene

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 …

Member Avatar for vegaseat
0
193
Member Avatar for hisan

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 …

Member Avatar for vegaseat
0
149
Member Avatar for KonkaNok

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.

Member Avatar for NETProgrammer
0
330
Member Avatar for vegaseat

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 …

Member Avatar for bumsfeld
2
494
Member Avatar for waterfox12
Member Avatar for Ancient Dragon

Ideal for folks who can't make up their mind which dessert to eat. Such an easy recipe!

Member Avatar for Portgas D. Ace
2
125
Member Avatar for jonhylever
Member Avatar for Ene Uran
-2
359
Member Avatar for HiHe

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 …

Member Avatar for vegaseat
1
170
Member Avatar for Zeruba

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.

Member Avatar for vegaseat
0
137
Member Avatar for blackrusader
Member Avatar for blackrusader
2
324
Member Avatar for sergent

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!

Member Avatar for iret
0
135
Member Avatar for mekhoo
Member Avatar for vegaseat
0
122
Member Avatar for almostbob
Member Avatar for almostbob
2
403
Member Avatar for ineedhelpasap
Re: PIL?

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]

Member Avatar for vegaseat
0
161
Member Avatar for ineedhelpasap

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]

Member Avatar for ineedhelpasap
0
88
Member Avatar for Thropian

This short code might just give you a hint: [url]http://www.daniweb.com/software-development/python/threads/191210/1558321#post1558321[/url]

Member Avatar for Thropian
0
2K
Member Avatar for ret801

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 …

Member Avatar for hondros
0
230
Member Avatar for vegaseat

I would say Disney World. I always have a good time there. However, a "cow tipping" excursion into Wisconsin sounds like fun too!

Member Avatar for jwenting
1
160
Member Avatar for Celtrix

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 …

Member Avatar for vegaseat
0
151
Member Avatar for [V]

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]

Member Avatar for vegaseat
0
156
Member Avatar for radical43144

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]

Member Avatar for woooee
0
151
Member Avatar for Drau

[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]

Member Avatar for Drau
0
169
Member Avatar for potchi

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 …

Member Avatar for vegaseat
0
1K
Member Avatar for rayden150

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.

Member Avatar for vegaseat
0
167
Member Avatar for cool0329

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.

Member Avatar for raptr_dflo
0
432
Member Avatar for kiracho

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 …

Member Avatar for vegaseat
0
315
Member Avatar for jingda
Member Avatar for WolfShield
Member Avatar for iamthwee
0
384
Member Avatar for VulcanDesign
Member Avatar for [V]

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]

Member Avatar for vegaseat
0
133

The End.