3,386 Posted Topics
Re: at least you are comparing number to string. EOF is empty string '' in Python. | |
Do you know that there is clean way of doing what C-language ternary operator ? does in Python's recent versions. It is if with special twist. The syntax is: [CODE]'The value if true' if <condition> else 'Value when false'[/CODE] Values can be any type. You can put this structure to … | |
Re: How about this if your code is right (need only simple length, not need to count each word only once, sort or something) ((code) button is useful for posting readable programs): s="""An Oligonucleotide is a short segment of RNA or DNA, typically with twenty or fewer bases. Although they can … | |
Re: You could check places like [url]http://python.computersci.org/Fundamentals/TheBasics[/url] or [url]http://www.razorvine.net/python/PythonForJavaProgrammers[/url] Which try to explain Python for people with Java background For using of classes, it is best to try to read some example programs, like [url]http://www.daniweb.com/code/snippet216596.html[/url] | |
Re: You must give the page html at least to check it out by somebody with experience in web pages (more than me). | |
Re: I just can not understand structure of organizing modules. Usually level two would be created on completion of level 1, either in chain fashion or by returning control to the main loop. | |
Re: Could we get one 'im' as sample to do true test of the function? Use attachment and zip the file if it is not accepted as it is (GIF?) | |
Re: I like this suggestion of random number n between 0..364 and comparing to set of earlier generated birth day numbers, and then converting to Month/day acccording to list of days until end of month of each month of year (or using built in function to calculate date n days after … | |
Re: [CODE]for bunchofhex in [r'\x45\x23\x67',r'\x123456']: print bunchofhex bunchofhex = bunchofhex.split(r'\x') print bunchofhex value = int('0x'+''.join(bunchofhex),0) print '%i = 0x%x' %(value,value) print '-'*40 [/CODE] | |
![]() | Re: Quite same as Gribouillis but here anyway (find_dup as generator, here put to list by list()): [CODE]L = [ 'oranges' , 'apples' , 'oranges' , 'grapes', 'oranges' ] def has_dup(li): return len(li) != len(set(li)) def find_dup(li): s= set() shown = set() for item in li: if item in s - … |
Re: I think nobody tries to be nasty. However I little generalized and gave up using find in my old multisearch. I think this parsing could be useful start. [CODE]inp=['2x+x','2x-1y+3x+2'] def multis(s,text,start=0): x='' for ch in text[start:]: if ch in s: if x: yield (x,ch) else: yield ch x='' else: x+=ch … | |
Re: I would little clean up -ordi- code: [CODE]def binary_search(a, required): start = 0 end = len(a) - 1 answer = None while start <= end: middle = (end + start) / 2 if a[middle] == required: answer = middle break elif required < a[middle]: end = middle - 1 else: … | |
Re: My opinion is that it can be done [B]without[/B] re. [CODE]# tested with python 2.6 and 3.1 sentences = """ You would stomp <mob> into the ground. <mob> would be easy, but is it even worth the work out? No Problem! <mob> is weak compared to you. <mob> looks a … | |
![]() | Re: After few proofs I found this way: [CODE]>>> s = '34, 58' >>> print ( tuple( int(i) for i in s.split(', ') ) ) (34, 58) >>> [/CODE] |
Re: Here is generator solution: [CODE]def xox(n): if n==0: yield '' elif n==1: yield 'X' yield 'O' else: for start in xox(n-1): if not start.endswith('O'): yield start+'O' yield start+'X' print 'xox(5) = ',list(xox(5)) [/CODE] [CODE] ['XOXOX', 'XOXXO', 'XOXXX', 'XXOXO', 'XXOXX', 'XXXOX', 'XXXXO', 'XXXXX', 'OXOXO', 'OXOXX', 'OXXOX', 'OXXXO', 'OXXXX'] [/CODE] | |
Re: Have you read this documentation? [url]http://docs.python.org/library/posixfile.html[/url] | |
Re: [CODE]>>> hex(234235) '0x392fb' >>> int('0x392fb',16) 234235 >>> 234235 << 4 3747760 >>> hex(_) '0x392fb0' >>> a=0x00E2 >>> b=0x0F80 >>> print hex(a & b) 0x80 >>> [/CODE] | |
Re: Something like this: [CODE]# -*- coding: cp1252 -*- from Tkinter import * from ScrolledText import * def filein(): ## mainObject.file2List(textFile.get()) mywin = ScrolledText() mywin.pack(fill=BOTH, expand=YES) mywin.insert(END,open(textFile.get()).read()) win = Tk() win.title("Upprepade ord") textFileButton = Button(win, text = "Läs in") textFileButton.grid(row = 2, column = 2) textFile = StringVar() textFileEntry = Entry(win, … | |
Re: Check my pretty lib for list and tuple for inspiration (see code snippets). | |
Re: If you learn simple list comprehensions you can do simpler way (python 2.6) [CODE]for limit in (-1,1,3): print [y in x if y>limit][/CODE] | |
Re: Task has no connection to line count only total number of characters collected except # lines. Here if all characters are included in the count including (excluding exception handling, without using with) does not work if file is shorter than 1000 chars (one line fix, exercise for the student): [CODE]def … | |
Re: Hint: [CODE]line='Fred, Nurke, 16, 17, 22' line=line.split(',') numbers=[float(mark) for mark in line[2:]] average = sum(numbers)/len(numbers) print "%s, %s: %.1f" % (line[0],line[1], average) [/CODE] | |
Re: Make sure the encoding of text file is plain ascii. | |
Re: Maybe could adapt my earlier multimatcher to be more restrictive: [CODE]# multiple searches of a string for a substring # using s.find(sub[ ,start[, end]]) import string def multis(search,text,start=0): while start>-1: f=text.find(search,start) start=f if start>-1: if ((text[start-1] not in string.letters) and (text[start+len(search)] not in string.letters)): yield f start+=1 paragraph = '''This … | |
Re: Unicode string has potentially very many letters that does not fit to ASCII range. utf8 however can encode them in variable length codes (Python 2.6, python 3 has many changes for the system) [CODE]a=u'asfasdfö' b=a.encode('utf8') print a print b [/CODE] However wikipedis says: [QUOTE]The Python language environment officially only uses … | |
Re: You forgot your code and or pseudo code. Also it is good to use the code tags (# button in toolbar) to put output text in post as it gets messed up, even it is not really code. If you put any one formatting in it for any part of … | |
Re: Please not use tabs. [CODE]import sys, os def cat(filename): f = open(filename) text = f.read() print '----', filename print text args = sys.argv[1:] for arg in args: cat(arg) [/CODE] | |
Re: Print is debuggers best friend [CODE] import string values=['']*6 values[5]="12234.7B" holder=[] print string.letters print values print values[5].letters holder.append(values[5].letters) [/CODE] | |
Re: totalTime is variable and it can not be called as function as it has not function value. | |
Re: if you want to really copy iterable, you should use slice: [CODE] returnDataArray = dataArray ==> returnDataArray = dataArray[:][/CODE] | |
Re: Do you need to take from every list? 6 is only number in two lists. Why can not take 4 from third list? | |
Re: Go from small to big in implementation, from the whole to parts in writing the pseudo code of things to do. Read the pseudo code and play stupid (i.e. computer), can you arrive in solution or did you miss something? Implement function, do test in main routine to test it … | |
Re: berol is both object instance and parameter to method, which already has self parameter. I would organize location for a object as its property and moving to other location with only one parameter, the destination. Object instances would be occupant values of one place instance. Object would move by giving … | |
Re: You need maybe something like this [url]http://eyed3.nicfit.net/[/url] | |
Re: ord is built in function to find numeric value of character, please rename the object instance. Why there is this order instance in class level common to all orders? Looks like you are replacing old orders every time new order is made, but then how do you know about earlier … | |
Re: Hint: [CODE]data='$ 235.0 M' print data.lstrip('$ ') print data.rstrip(' M') [/CODE] | |
Re: You need to put global known in your function. put [ICODE]t0=time.clock()[/ICODE] before and after [ICODE]print time.clock()-t0[/ICODE] to see how long it took. But put the timing in main function as you need total not time for each call of fibonacci. Nice example of lookup function. | |
Re: put lower() after read().: [ICODE]words = set(open('mispel.txt').read().lower().split())[/ICODE] Do you need to suggest correct spelling for the incorrect words? | |
Re: I could not quite fathom your code but I did the following: [CODE] # For storing information about auctions class AuctionList: def __init__(self,data=[]): self.auctionData=data # Add an auction to the list def Add_Auction(self,info): print 'Before',self.auctionData self.auctionData.append(info) print 'After',self.auctionData def __len__(self): return len(self.auctionData) def __str__(self): return str(self.auctionData) auction2=AuctionList(['line 1']) auction_list=AuctionList(['line 1']) … | |
![]() | Re: I would prefer to formulate the SoulMazer's code like this [CODE]#!/usr/bin/python text1 = "user" # Change to whatever you would like f = open("D:/Python26/LICENSE.txt", "r") for lineno,line in enumerate(f.readlines()): if text1 in line.lower(): print "Word found at line", lineno+1 [/CODE] ![]() |
Re: I do not know if this filter is enough exclusive as I do not check the length of numbers but: [CODE]test= '100|1999|pepito|False|27-10655374-1|False|||05/09/1952|1|4||3||1|1|8|67||4|False|True|False|oerirabtaa||||Femenino|0|0|0|0|0|0|2|' testlist = test.split('|') for t in testlist: if t.translate(None,'0123456789')=='--': ## take out all numbers and compare print t """ Output: 27-10655374-1 """ [/CODE] | |
Re: Like this: [CODE]>>> a='010101010101010101010101010101010101010101010101010101010101' >>> a=int(a,2) >>> a 384307168202282325L >>> [/CODE] | |
Re: [QUOTE=Tech B;1228060]testzip is to check the integrity of the files within the zip. To check if a zip itself is corrupt, pass it through a try statment. [code] import os, zipfile mylist = os.listdir("C:\myzipfiles") [/code] [/QUOTE] Little less stupid listing [code] import os, zipfile mylist = [zip for zip in … | |
![]() | Re: Alternatively chdir to directory before import. Your must user __import__() function not the statement. However it is little strange that you would need to do what you are asking. Could you maybe introduce the function of your program in rough pseudo code so maybe we could find you better alternative … |
Re: This is Python forum. Show effort to write the code and in case of problems post to Pascal/Delphi group your code and description of your problem. Luck with coding! | |
Re: This way you can find those names, just replace your action in place of print. [CODE]inp="""Share name Type Used as Comment -------------------------------------------------------------- Data Disk Data2 Disk My Docs Disk Users Disk The command completed successfully.""" for line in inp.splitlines(): if line[14:18]=='Disk': print line[0:13].rstrip() """Output: Data Data2 My Docs Users """ … | |
Re: There is this one small unknown web service called YouTube for example: [url]http://digg.com/programming/YouTube_is_almost_entirely_written_in_Python[/url] | |
Re: You can say also [CODE]my_array='a'+479*'b'[/CODE] | |
Re: Your code is quite well, anyway two more ways to do it: masking with 0b1111 and using the bin representation string: [CODE]## 1) do it yourself with masking def nibble(n,x): ## mask 0b1111 shift up, mask, shift back return ( x & ( 0b1111 << (4 * n) ) ) … | |
The End.