3,386 Posted Topics
Re: Why not ftp? Or basic http open? [CODE]data = open('OutputFile.txt').read() f = urllib2.urlopen(url, data)[/CODE] | |
Re: I do not understand class without init also push code before pasting code. | |
Re: Maybe this consolised piece of code can help something: [CODE]def searchfilt(): text = raw_input('Please choose a highlighter search term:\n') for i, line in enumerate(["1280320019","u'Search Appointments at DkIT'", "u'https://recruit.ancheim.ie/dkit/rec/erq_search_package.search_form?p_company=1&p_internal_external=E&p_display_in_irish=N'", "Firefox History","Normal Time"]): if text in line: a,b,c = list(line.partition(text)) print(''.join((a,'<strong>',b,'</strong>',c))) ## c can have second hit else: print line searchfilt() [/CODE] | |
Re: simple: [CODE]>>> a='Cadillac' >>> answer=[a] >>> answer ['Cadillac'] >>> b, = answer >>> b 'Cadillac' >>> [/CODE] b, means singleton tuple, tuple with one element, | |
Re: Maybe the poster liked to have list containing integer length instead of the element for every element of the list. Then for line 5 use statement to return list of counts. What happens or is supposed to happen if the elements are numbers? Maybe len(str(element)) is better to add to … | |
Re: At least here is little refactoring to loop and function and usefull sum to terminal window: [CODE]from graphics import * def makeinput(win,i): #Item and Price input maker center2 = Point(50,50*i+50) label2 = Text(center2, "Item >>") label2.draw(win) input2 = Entry(Point(170,55+i*50), 20) input2.setText("item") input2.draw(win) centera = Point(350,50) labela = Text(centera, "Price >>") … | |
Re: [code]with open('binfile.dat', 'rb') as bf: bf.seek(10) open('out.dat', 'wb').write(bf.read(80))[/code] Something like this. This is untested as I am not with computer now. Maybe you must seek(9) and/or read(81). | |
Re: use statement like: [code]if this_key in my_dict: my_dict[this_key].add(this_value) else: my_dict[this_key] = {this_value}[/code] | |
Re: You can split records from \t and put first records to set and then same from other file and for each record which is in second file which has same key field put in result. Gribouillis did nicely that he checked for uniqueness of the keys as text file is … | |
Re: Use normal double quotes instead of triple single quotes for multiple lines. | |
Re: [QUOTE=woooee;1285517]You would have to use Tkinter or one of the other toolkits. An example [url]http://tkinter.unpythonic.net/wiki/AutocompleteEntry[/url][/QUOTE] Broken link. | |
Re: [CODE]import datetime today = datetime.date.today() time_to_stay = int(raw_input('Number of days you want to stay: ')) future = datetime.timedelta(days=time_to_stay) expire = today + future print(expire) [/CODE] | |
Re: Also it is not very good choice to change the meaning of [URL="http://www.daniweb.com/code/snippet216520.html"]map function[/URL] to dictionary, even it is inside function. Could give you bad habit that bites back later. | |
Re: I also think that the action of using int function or as hidden by round, is disruptive as it is very discontinuous by its very nature. Sometimes it is better to stay with integers and be clearly discontinuous. Same could be done, maybe by multiplying numbers by some constant before … | |
Here is my practise with [URL="http://www.boggled.org/"]boggle [/URL]letter square non-overlapping word finder after some drastic debugging and cleaning. I think it is reasonable speed also. Comments wellcome. | |
Re: Could you post beginning of the original csv file or attach it from advanced view, manage attachments? I would guess that delimeter is ',' | |
Re: EDIT: Code tags added I have just started to learn python (Learning Python), and I am trying to move some files to another folder that are over a week old. I keep getting an error about the files not existing. [CODE] import shutil, sys, time, os src = 'c:/users/wca36050/temp1' dst … | |
Re: you must test for each number which is prime. You can stop checking when the prime**2 is bigger than maximum value of candidates. To be sure to find the 1000 use for example list of 100 000 truth values all True in beginning. Then take each prime*n (every nth) by … | |
Re: Corrected your finishing tag to (/code) from Queue import PriorityQueue #making the priority queue object pq = PriorityQueue() #making the different dictionaries firstDict = {'boy':'short', 'girl':'tall'} secondDict = {'man':'tall', 'woman':'short'} #putting the objects in the priorityQueue with a priority number pq.put(secondDict,2) pq.put(firstDict, 1) #printing the dictionary according to their priority … | |
Re: See the yesterdays post of vegaseat in the GUI thread. | |
Re: You do not need to push even tab most times as reasonable editors know Python indention style, even 4 spaces is the default tab width. Mostly I hit this isssue when I try code in IDLE command line and want to copy it over to my program file. | |
Re: In Python you can call the function, which is defined after another without forward definitions. However the function must be defined before main code calls it. It is bad practise to put main code before definitions except for some variable definitions. [CODE]def a(p): if p>4: b(p) else: print "a", def … | |
Re: And for the beauty of recursion you can try: [CODE]def wordReverse(word): if not word: return word ## empty sequence is already reversed else: return word[-1]+wordReverse(word[:-1]) print wordReverse('Python newbie')[/CODE] And the classic "vegaseat's" [CODE]def wordReverse(word): return word[::-1] # -1 step from default start to default end [/CODE] | |
Re: Unfortunately the answer in snippsat's nice post is sorting alphabetically, not by length. Here fix and list comprehenision to do the same. [CODE]def wordPop(text, n): nwords = [] words = text.split() for word in words: if (len(word) >= n): nwords.append(word) return sorted(nwords, key=len, reverse= True ## if longest first ) … | |
Re: Accepted wisdom in Python circles is not to use xml if it is not forced to you for compatibility with programs or systems out of your control. | |
Re: [CODE]def squareEach(nums): return [i*i for i in nums][/CODE] | |
Re: You could divide the job in small enough pieces and check for parameter change and pause after each piece. You should separate parameter entering in separate thread so it stays active during execution. | |
Re: [code]print('\n'.join((str1, str2, str3))) [/code] maybe? | |
Re: Check out [url]http://docs.python.org/library/email[/url] | |
Re: Code of how you generated and saved the database in first place, could be helpful. I don't know so much, but others could get better idea for the reason of this happening. | |
Re: Good place for mac installers seem to be for example: [url]http://pythonmac.org/packages/py25-fat/index.html[/url] Seems to be for elder version of Python though. | |
Re: Check this documentation: [url]http://www.tkdocs.com/tutorial/windows.html[/url] | |
Re: [QUOTE=bob47910;1282262]If I created Tkinter window with some text that filled the whole window and now wanted to replace the window with a new text, is there a way to refresh the window? For Example: a= 100 win= Tk() win.geometry("500x300") while a > 0: if a%2 == 0: lbl = Label … | |
Re: If the input value is in variable info: [CODE]>>> info.split('\n',1) ['>sp|P20905|5HT1R_DROME 5-hydroxytryptamine receptor 1 OS=Drosophila melanogaster GN=5-HT7 PE=2 SV=1', 'MALSGQDWRRHQSHRQHRNHRTQGNHQKLISTATLTLFVLFLSSWIAYAAGKATVPAPLV\nEGETESATSQDFNSSSAFLGAIASASSTGSGSGSGSGSGSGSGSGSYGLASMNSSPIAIV\nSYQGITSSNLGDSNTTLVPLSDTPLLLEEFAAGEFVLPPLTSIFVSIVLLIVILGTVVGN\nVLVCIAVCMVRKLRRPCNYLLVSLALSDLCVALLVMPMALLYEVLEKWNFGPLLCDIWVS\nFDVLCCTASILNLCAISVDRYLAITKPLEYGVKRTPRRMMLCVGIVWLAAACISLPPLLI\nLGNEHEDEEGQPICTVCQNFAYQIYATLGSFYIPLSVMLFVYYQIFRAARRIVLEEKRAQ\nTHLQQALNGTGSPSAPQAPPLGHTELASSGNGQRHSSVGNTSLTYSTCGGLSSGGGALAG\nHGSGGGVSGSTGLLGSPHHKKLRFQLAKEKKASTTLGIIMSAFTVCWLPFFILALIRPFE\nTMHVPASLSSLFLWLGYANSLLNPIIYATLNRDFRKPFQEILYFRCSSLNTMMRENYYQD\nQYGEPPSQRVMLGDERHGARESFLD'] >>[/CODE] | |
Re: Your code is not in context but this seems to function normally for me in Python 3.1 [CODE]def fun(): try: fdjalsd # bla bla... except Exception as e: # here I got error message "Invalid Syntax" in the comma print('Handler, error:',e) return False print(fun()) """Output: Handler, error: global name 'fdjalsd' … | |
Re: [URL="http://embraceubuntu.com/2006/12/16/gnome-open-open-anything-from-the-command-line/"]This link[/URL] says: [QUOTE]Simply put, the command gnome-open opens the item specified by the url with the preferred GNOME app for that file/mime-type. In a sense, this command resembles the universal “open” command on Mac OSX.[/QUOTE] So Mac is supposed to have [iCODE]open[/iCODE] command | |
Re: [CODE]try: value=int('surely not number') except ValueError as e: print e[/CODE] | |
Re: The SQL statement is string, so you can probably do something like: [CODE]num_title=54 headerline=','.join("Header%i" %i for i in range(num_title)) ## take in reality from header sql="CREATE TABLE IF NOT EXISTS (%s)" % headerline print sql [/CODE] | |
Re: Like this seems to work, but I do not know if it is easiest. If you use Python 3, surely there must be cleaner alternative using dictionary comprehensions. [CODE]import operator d1 = dict() d1[0] = 1 d1[1] = 2 d1[2] = 2 maxValue = max(d1) print [key for key in … | |
Re: For most needs Python list correspond with array. You can split fields by line.split('\t'). You can test if value is in field by in and usualy also strip and lower methods come handy. | |
Re: Your running environment is Linux? What readline functions are you using? Some piece of example code, maybe? Have you tried the curses support? [URL="http://docs.activestate.com/activepython/2.5/python/curses/curses.html"]Curses Programming with Python[/URL] | |
Re: 1) Because they are different modules: [CODE]>>> import Tkinter >>> Tkinter <module 'Tkinter' from 'D:\Python27\lib\lib-tk\Tkinter.pyc'> >>> import tkMessageBox >>> tkMessageBox <module 'tkMessageBox' from 'D:\Python27\lib\lib-tk\tkMessageBox.pyc'>[/CODE] Second question I don't know to answer. | |
Re: For example that first line of first file looks different format (bold finishing tag before but no starting tag), otherwise, is it so that yo want to pick identifier between > and | psoition 1:9, (>sp|P20905| > id = sp|P20905) and when it is found take start and end indexes … | |
Re: Is there not way to hide instead of close the window in QT? Then you could create window hidden and then only show it when needed and afterwards hide it again. If that window have different menus and even tool bar, I would call it different application and implement it … | |
Re: I do not know about regex magic so much, but here is my plain Python code, if it may help you: [CODE]sents= ('open red box with key','open red box','open box', 'open box with key') for sentence in sents: sentence = sentence.split() print sentence verb, obj = sentence.pop(0), sentence.pop(0) ## object … | |
Re: use: [CODE]for line in data_list: print(line)[/CODE] Python indexes start from 0 but you can add one to them when you need them or insert for example '' or [] as first (zeroth) element. You can use partition with two new lines to separate the groups in file first and split … | |
Check this out: [URL="http://www.lfd.uci.edu/~gohlke/pythonlibs/"]Unofficial Windows Binaries for Python Extension Packages[/URL] | |
Re: Generator is function which 'freezes' for every result and yields it, when next answer is requested function is 'unfrozen' with all the local state. When all answers are finished the iterator gives StopIteration exception and does not give more results. Sequences that are iterable have method called __iter__ and that … | |
Re: > this is what I have in my module Push the (CODE) button before pasting, please! import time print('Hello World!!!!') time.sleep(1) print ('what is your name?') name = input() a = ('Hello ') b = (' my name is com') string = a+name +b print (string) time.sleep(2) print('What is your … | |
Re: And there is also form of raw string: [CODE] sys.stdout.write(r"123: The metro polis\n")[/CODE] |
The End.