851 Posted Topics

Member Avatar for Wire.Crisis

You are right, for a large range hughesadam_87 outstring code would make the most sense. Writing to disk so many times would be slow.

Member Avatar for Lardmeister
0
408
Member Avatar for DustinS

With the advent of Python3 your life is easier: # test binary file read fname = "ball.png" with open(fname, mode='rb') as f: data = f.read() print(type(data)) ''' result with Python2 >>> <type 'str'> result with Python3 >>> <class 'bytes'> '''

Member Avatar for Gribouillis
0
2K
Member Avatar for Lardmeister

This little experiment with Tkinter and pixel drawing shows some strange effects (look at line 27 comments!!!): '''tk_put_pixel.py place a pixel at pos=(x,y) with color=(r,g,b) on an image area note: one pixel might be hard to see, so create a series of pixels (line) ''' try: # Python2 import Tkinter …

0
148
Member Avatar for favoredanteater

Please enter your code in a code area to preserve the indentations. Try: R1 = Rectangle(width, height) after your input statements

Member Avatar for Schol-R-LEA
0
210
Member Avatar for Inshu
Member Avatar for Lardmeister
0
753
Member Avatar for whoisstanley

Or you can create a little container class: '''dict_bag_of lists.py use a Bag container class to store lists that belong together tested with Python27, Python32 ''' class Bag_Dict(object): """ simple key mapped container for lists that belong together list1 = [1, 2, 3], list2 = [4, 5, 6], ... """ …

Member Avatar for Lardmeister
0
185
Member Avatar for idRATHERgoHUNT

Buy yourself a deck of cards, it's almost free. You can play at least 47 different games with it.

Member Avatar for remixedcat
-2
2K
Member Avatar for combiana7
Member Avatar for Lardmeister
0
97
Member Avatar for predator78
Member Avatar for M.S.

Another way: # find one of the longest words in a text from string import punctuation as punc def find_longest(text): word_set = set(word.strip(punc).lower() for word in text.split()) return max((len(word), word) for word in word_set) text = """Python is probably one of the few programming languages which is both simple and …

Member Avatar for M.S.
0
310
Member Avatar for hotblink

hotblink (Christopher Dela Paz) you should give at least an attempt to code this yourself. Most of us frown on doing homework for you.

Member Avatar for Xantipius
0
442
Member Avatar for crishein14

Meister snippsat's solution is easy, but be careful, it will rename any .png file in the directory. You might want to make sure that the name starts with an integer at least.

Member Avatar for M.S.
0
173
Member Avatar for toyotajon93

Try this: for data in result: print type(data) If it is type string then do: for data in result: # converts the string to list object data = eval(data) print data[0][:3] Look at this: data_str = "[278, 278, -1, [25076, u'', 3, 6, u'', 0, 0, 1, 0, 0,0, u'', …

Member Avatar for vegaseat
0
196
Member Avatar for deepthought

You might use something like this: list_hex1 = ['12AF', 'B3D9', 'A5CC', '6EA1\n', '298F', 'A005\n'] # strips off white spaces list_hex2 = [item.strip() for item in list_hex1] print(list_hex1) print(list_hex2) '''result --> ['12AF', 'B3D9', 'A5CC', '6EA1\n', '298F', 'A005\n'] ['12AF', 'B3D9', 'A5CC', '6EA1', '298F', 'A005'] '''

Member Avatar for deepthought
0
404
Member Avatar for Lardmeister

To print on the same line Python2 uses print item, Python3 uses print(item, end=' ') Is there a way to make it work in both versions?

Member Avatar for Ene Uran
0
244
Member Avatar for python1956

You are trying to use a Python sort() on a numpy array. To gert this to worek you have to convert the numpy array to a Python list first. Try something like mynparray.tolist()

Member Avatar for Lardmeister
0
4K
Member Avatar for M.S.

Interesting project. You can also do this with sets and use set_oldnames.intersection(set_newnames). I tried it and got 11 names to match.

Member Avatar for vegaseat
2
273
Member Avatar for duyencaothi
Member Avatar for Max00355
0
179
Member Avatar for beela16

Here is way to enter a list of numeric values: http://www.daniweb.com/software-development/python/threads/20774/starting-python/17#post1855632

Member Avatar for Lardmeister
0
287
Member Avatar for brajesh79

Glad you solved it. I suspected the space in the directory name that gives Windows a hard time every now and then.

Member Avatar for Lardmeister
0
15K
Member Avatar for vegaseat
Member Avatar for WolfShield

Smoking is an addiction, and even very smart people can get addicted.

Member Avatar for BitBlt
0
250
Member Avatar for GrimJack

[QUOTE=vmanes;1192179]I am never getting that old. Never.[/QUOTE]I am not an expert on this subject, but I always thought that it takes two or more for real sex. You might be the only willing person in this scenario.

Member Avatar for vinnitro
1
3K
Member Avatar for vegaseat
Member Avatar for TrustyTony
Member Avatar for Lardmeister

Just a quick look at current US Dollar prices per US gallon of petrol in different parts of the globe: **US 3.85 UK 5.80 Norway 6.30 France 5.55 Japan 4.25 Russia 2.10 Kuweit 0.80 Venezuela 0.12**

Member Avatar for Stuugie
1
178
Member Avatar for sneekula

Java with its forced OOP is suited for simple stuff for children. Python has been mostly used to solve adult scientific problems.

Member Avatar for Sanchixx
0
482
Member Avatar for 4evrmrepylrning

A while loop beats recursion in speed and simplicity: import re subs = [] data = 'ABC <uvw <xyz some random data' while True: match = re.search(r'(<[a-z]{3})', data) if match: subs.append(match.group(0)) data = data.replace(match.group(0), '') else: break print("data = %s" % data) print("subs = %s" % subs) ''' data = …

Member Avatar for TrustyTony
0
212
Member Avatar for G_S
Member Avatar for TrustyTony
0
3K
Member Avatar for DJWK

The NCIS TV show is made for moron's to watch, purely Hollywood fantasies. The only programming language that is smeared onto just about every computer is Java.

Member Avatar for MrUpsetter
0
258
Member Avatar for 4evrmrepylrning

Just a note. As your program gets larger, using `from Tkinter import *` can lead to difficult to trace namespace conflicts. It's better to use a namespace like `import Tkinter as tk`

Member Avatar for 4evrmrepylrning
0
1K
Member Avatar for idislikemacs

Zoee, looks like the top two lines of code slipped out of the code area. The new DaniWeb code handling is really a pith!

Member Avatar for memomk
0
147
Member Avatar for Ancient Dragon

I wanted to write something sensible, but the phone is ringing, most likely one of those pesky phonecalls from a political interest group. Ah, it's Barbara Bush telling me to vote for her friend Mitt!

Member Avatar for Ene Uran
1
189
Member Avatar for hypernova

The C function scanf() is notoriously unsafe and you have discovered this. In line(1) you are supposed to enter 2 characters. If you enter accidentally 3 characters, the input will flow into the next scanf(). To avoid that flush the input stream. In line(2) you should enter 2 integers separated …

Member Avatar for hypernova
0
302
Member Avatar for Ancient Dragon
Member Avatar for happygeek
0
103
Member Avatar for debasishgang7

Technically you want a **selection **which allows sequence items to be repeated, a **combination** or **permutation** does not: def selections(seq, n): """ selections(seq, n) is a recursive generator where seq is an iterable object n is the sample size n = len(seq) is the max sample size returns a list …

Member Avatar for TrustyTony
0
1K
Member Avatar for minimee120

> Karen 555-231-5437 898-340-9870 > Ala 212-889-0314 Maybe this will help a little: # raw data of name and phone number(s) with space separator data = """\ Karen 555-231-5437 898-340-9870 Alma 212-889-0314 Frank 555-245-5348 898-340-7890""" fname = "phonebook.txt" # write the raw data to a text file with open(fname, "w") …

Member Avatar for Lardmeister
0
235
Member Avatar for jackbauer24

Why not stick with Java and learn it to a point where you can actually use it? It's better to be an expert in one language than to be a fool in a handful of languages.

Member Avatar for Rashakil Fol
0
500
Member Avatar for McLaren
Member Avatar for Coloradojaguar
0
171
Member Avatar for McLaren

Flexibility and the willingness to learn new things is most important. Also stop watching TV, it is bound to make you stupid.

Member Avatar for Lardmeister
0
221
Member Avatar for how_too

> SalesPerson This should give you a start: # create a simple class SalesPerson class SalesPerson: # self keeps track of the instance def __init__(self, id, name, sales_list=[]): self.id = id self.name = name self.sales_list = sales_list # tom's list of sales for the last four months sales_list_tom = [2345.77, …

Member Avatar for Lardmeister
0
239
Member Avatar for memomk

Put all your import statements at the start of the code. Repeatedly importing within functions is inefficient and can lead to errors.

Member Avatar for memomk
0
2K
Member Avatar for minimee120

Now remember that the key of a dictionary has to be unique. Names with the same score have to processed so the names appear in a list. Here is an example how to handle key collisions: # has 2 names with matching scores data_str = """\ Mark 50 Adam 20 …

Member Avatar for Lardmeister
0
262
Member Avatar for vmars

Before we all get royally confused, it looks like **vmars** installed portable python in a directory that is usually used for the nonportable Python version.

Member Avatar for vmars
0
2K
Member Avatar for vmars

Unless you want to run Python from a Flashcard and use it between different Windows computers, you are better off to install Python properly with the Windows installer version you get from: http://python.org/ftp/python/3.2.3/python-3.2.3.msi Rename your portable python directory to "C:\PortPython32" and then run the python-3.2.3.msi installer file. Now your .py …

Member Avatar for vmars
0
2K
Member Avatar for fishsticks1907

# in Python you can swap variables via tuple packing a = 1 b = 2 # swap a with b a, b = b, a # now b = 1 and a = 2 # test print(a) print(b) # for clarity you may optionally surround the tuples with () …

Member Avatar for TrustyTony
0
250
Member Avatar for SpiritualMadMan

I think in C and C++ the & operator points to the string (array of characters). In Python that would simply be the string.

Member Avatar for Lardmeister
0
413
Member Avatar for vegaseat

I clicked 'Toggle Plain Text' before highlighting the code and pasting it into my editor (IDLE), then it runs just great.

Member Avatar for Mavericks
1
3K
Member Avatar for vegaseat

Lambda always intrigues me: [code]# works with IronPython, Python2 and Python3 d = 255 # a recursive dec to bin function d2b = lambda d: (not isinstance(d,int) or (d==0)) and '0' \ or (d2b(d//2)+str(d%2)) print(d2b(d)) # 011111111 [/code]

Member Avatar for Gribouillis
1
7K
Member Avatar for GrimJack

[QUOTE=jbennet;608083]Not on the street, but at work theres loads of cameras everywhere (staff theft issues) and i dont like being monitored all the time, its kinda opressive.[/QUOTE]You mean they are stealing members of the staff in England?

Member Avatar for Netcode
0
601

The End.