851 Posted Topics
Re: 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. | |
Re: 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'> ''' | |
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 … | |
Re: Please enter your code in a code area to preserve the indentations. Try: R1 = Rectangle(width, height) after your input statements | |
Re: A good example from Schol-R-LEA is worth a thousand words. | |
Re: 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], ... """ … | |
Re: Buy yourself a deck of cards, it's almost free. You can play at least 47 different games with it. | |
Re: name = "Smolski" id = "12345678" print(name[0]) # S print(id[-3:]) # 678 | |
Re: 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 … | |
Re: hotblink (Christopher Dela Paz) you should give at least an attempt to code this yourself. Most of us frown on doing homework for you. | |
Re: 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. | |
Re: 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'', … | |
Re: 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'] ''' | |
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? | |
Re: 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() | |
Re: 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. | |
Re: See: http://www.amazon.com/Python-For-Dummies-Stef-Maruch/dp/0471778648 | |
Re: Here is way to enter a list of numeric values: http://www.daniweb.com/software-development/python/threads/20774/starting-python/17#post1855632 | |
Re: Glad you solved it. I suspected the space in the directory name that gives Windows a hard time every now and then. | |
Re: Easy to convert to a music album manager. | |
Re: Smoking is an addiction, and even very smart people can get addicted. | |
Re: [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. | |
| |
Re: Pretty lame stuff, hard to vote for anything. | |
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** | |
Re: Java with its forced OOP is suited for simple stuff for children. Python has been mostly used to solve adult scientific problems. | |
Re: 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 = … | |
Re: see also: http://www.python-forum.org/pythonforum/viewtopic.php?f=2&t=14218 | |
Re: 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. | |
Re: 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` | |
Re: Zoee, looks like the top two lines of code slipped out of the code area. The new DaniWeb code handling is really a pith! | |
Re: 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! | |
Re: 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 … | |
Re: The rest of Europe is paying for the food these characters are throwing. | |
Re: 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 … | |
Re: > 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") … | |
Re: 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. | |
Re: Two 20 minute breaks each working day are best for me. | |
Re: Flexibility and the willingness to learn new things is most important. Also stop watching TV, it is bound to make you stupid. | |
Re: > 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, … | |
Re: Put all your import statements at the start of the code. Repeatedly importing within functions is inefficient and can lead to errors. | |
Re: 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 … | |
Re: 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. | |
Re: 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 … | |
Re: # 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 () … | |
Re: I think in C and C++ the & operator points to the string (array of characters). In Python that would simply be the string. | |
Re: I clicked 'Toggle Plain Text' before highlighting the code and pasting it into my editor (IDLE), then it runs just great. | |
Re: 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] | |
Re: [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? |
The End.