304 Posted Topics
Re: Some remarks... I would say that a function is auxiliary if it is called and used by a limited set of functions (methods, other callables) and does not provide functionality(meaning) on its own. If you write some date arithmetic module, then isleapyear appears not to be an auxiliary function. It … | |
Re: Yes, it is worse then the infamous: `not re.match(r"^1?$|^(11+?)\1+$", "1" * number_to_test)` birinci: There is nothing wrong with this algo. But computers (more precisely: functions using stack in the operating system) are not built the way, they can process this program efficiently. It is a leaking abstraction. Google it. | |
Re: Hopefully this is not a real loan approval software. | |
Re: Please read a basic python tutorial, write down in normal words what you expect form this class, and repost your code. Issues: * The some method's naming contradict the methods documentation (is_empty, is_full) * Different methods with the same code. * Semantically problematic code (insert) * I do not understand … | |
Re: I think this is the wrong question. Allow me to be philosofical. I advise you to consider the following wisdom: **A good programmer is smart and gets things done.** Consider this as a buddhist [quote](http://viewonbuddhism.org/resources/buddhist_quotes.html). **Smart** means to be brutally honest to yourself about whether you understand something or not. … | |
Re: I always learn new things. 1 lakh = 10**5 This is the recommended approach to open a file and handle it since python 2.7: with open("filename") as f: <handle content of the file> Otherwise rrashkin's solution is good for linear search. You say binary search in contrast to linear search. … | |
Re: > as close to the below as possible. As close to [that](http://code.activestate.com/recipes/576830-analog-clock/)? Are you learning turtle? Are you expected to do that in turtle? | |
![]() | Re: Please be more specific. Some ideas: > 1. numbering the lines in the file? with open('output.txt', 'r') as f for line_number, line in enumerate(f): pass # do something with the line > 2. finding this table if line.startswith("Comparison of initial and final structures :"): table_begin=True if table_begin and line.startswith("------"): table_end=True … |
Re: I wouldn't pollute the main namespace with arbitrary variables. I provided this in comments. First you have to convert the input string into a dictionary. Then you can update some objects namespace with this dictionary. class Importedvalues(object): pass i=Importedvalues() vs='variable1=5&varible2=3&variable3=27&varible4=1' vs_modified=dict() for statement in vs.split("&"): varname,value=statement.split("=") vs_modified[varname]=value #locals().update(vs_modified) vars(i).update(vs_modified) print … | |
Re: Offtopic post, in the offtopic topic. As others pointed out, software is always part of larger system which involves interfaces to other softwares, people, and in the end the mother nature. In my opinion hacking is: Persuade a system to do something not normal, something out of ordinary, something not … | |
Re: Your function does what zip builtin function does. Just much more inefficiently. It takes iterables, and return a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. The returned list is truncated in length to the length of the shortest … | |
Re: You should put directories into the path variable. Python.exe is not a directory. http://docs.python.org/3.3/using/windows.html | |
Re: Well. I don't know where to begin. There is too much code. Seriously. Please consider not to repeat almost the same code for every difficulty. You can factor it out, and make the whole thing better. Like this: import random import time from collections import namedtuple def get_int(prompt=""): while True: … | |
Re: Using csv does not help, because there isn't a single comma in the input. The first row in the output is: 11 hour, 38 min, 47 sec. So the seconds are: `11*60*60+38*60+47= 4197` How is 44700 calculated? What is that? Something like this: with open("conv.csv","w") as fo: with open("time.csv") as … | |
Re: Because for every number n the following is true: n!=1 or n!=2 Clear thinking? | |
Re: *How would I add the user username to the dictionary so that the username can be displayed on the logged in page?* You make session["username"]=username in checkLogin if login is successfull. However. This is not a session. Session is a set of dictionaries that is present for each user (anonym … | |
Re: If the user can guess infinitely, then an infinite loop (or infinite recursion) seems to be adequate. What is the expected operation of the program? The code seems to contain: * You have a one (?) character long Word * You ask the user to quess(guesschar). * If the quesschar … | |
Re: Without knowing what the problem at hand is... The preferred way of reading a file line by line is: with open('filename.txt') as fp: for line in fp: print(line) Your code opens program0.4.txt, reads everything into a string. Then you split this string by space and enter. So your line variable … | |
Re: You define four dictionaries: sum_temperature day-> sum of temperature on the given day count_temperature day-> count of temerature data on given day likewise with moisture. You read in the file line by line. You parse one line into day, temerature, moisture. Time and precipitation is not needed for the task. … | |
Re: Check out [this.](http://www.daniweb.com/software-development/python/code/217082/eratosthenes-sieve) There are highly optimized codes there for generating prime numbers. Including my one :) They give you primes to 10**6 in seconds. If you post your code we can pinpoint, why is it so slow. | |
Re: Oh, come on. Don't demand us to find out what the task is, then solve it. If you cannot answer your own question by using paper and pencil, then you cannot solve it in python either... | |
Re: You need to define what a star IS. Read [this](http://en.wikipedia.org/wiki/Star_polygon) Basically you have n points and you should make cyclic [arithmetical sequence](http://en.wikipedia.org/wiki/Arithmetic_progression) that contains all the points and have a difference more then 1 (in case of a square and triangle it can be 1). For example for a poligon … | |
The most efficient static sieve generator in python I have seen so far. Returns the list of primes, that are not greater than n. | |
Re: I read the docs quickly. If I read it correcty, there is no advertised funkcionality in modemdriver.py, that allows you to use it as a library. As you said it. If all else fail you can construct the command line and the files needed in python, and run the whole … | |
Re: Some remarks: You do not handle incorrect input. If this is your intention, then this is ok. The lines from 5-24 can be written: `smallest,bigest=min((f,s,t)), max((f,s,t))` | |
![]() | Re: > 'm also a Python-starter. Question to the OP: What is the purpose of following function? > > def calculate_gpa(numbercourses): coursenumber = 1 > > It returns nothing; None I guess. > It does nothing with the parameter numbercourses. > It sets a variable(global?) coursenumber to 1. Yes it returns … |
Re: The link contains a rar file containing an exe. How is it supposed to run in linux? | |
Re: Please try to reformulate your question. Your program inserts something into a database. You can do anything after that... What is an "event"? | |
Re: What is a counted file? Please provide a testcase. For example you can count newlines and characters like this: infilename = input("Enter the name of the file:") count_newlines=0 count_chars=0 with open (infilename ,'r') as infile: for line in infile: count_newlines+=1 count_chars+=len(line) print(count_newlines) print(count_chars) | |
Re: Try [selenium](http://docs.seleniumhq.org/) or [mechanize](https://pypi.python.org/pypi/mechanize/). | |
Re: You are very far from the solution. Maybe you should try a much easier task first. For example you have no working code. You create a wallet, a lock and a global variable and define two functions. You have a syntax error at line 4 because there is no right … | |
Re: First of all, if you have to return "set3" or similar, then you have to have it available as a data. My quick and dirty solution is below: from collections import defaultdict data={"set1":["01","34","29","16"], "set2":["45","88","19","17"], "set3":["56","21","57","20"], "set4":["29","42","89","08"], "set5":["19","45","56","20"], "set6":["85","56","33","78"]} positions=defaultdict(set) # which value, in which positions: which sets allvalues=set() # which … | |
Re: Create a html page, that contains what you want. Create a python program, that creates that html page for you as a string. Go to cherrypy [documentation.](http://docs.cherrypy.org/stable/concepts/basics.html). Instead of returning "Hello world", reaturn the html page, that you have previously created. | |
Re: Can you provide the expected output? What is a command variable? What is a dictionary level? What I understand is that the first two lines should be stored as: data={"B":( (128.9,"hello"), (1918.1,"hi"), (2938.2,"world"), ), "H":( (12.2,"India"), (218.6,"Lost"), (29.9,"Place"), ) } | |
Re: *Min function does not return an int.* Min function gets a sequence and returns the lowest element of that sequence. In that case this sequence is a list of (distance, coordinates) pairs. If you have a list of distance and coordinates like: [(12,(1,2)), (1,(12,25)), (0,(1525,13))] It will return the (0,(1525,13)) … | |
Re: Your code has hardly anything to do with the task you mentioned in the first post. Try to program the following procedure in python. Let's make two variable that will store the number of tails and heads. Let they be: numtails=0, numheads=0 Loop begins here. Count 100 times. For each … | |
Re: You do not get this error when you iterate over the elements of a set. elements={1,2,3} for each in elements: print each You do not get this error when you convert a set to a list. `listelements=list(elements)` You **do** get this error, when you try to index a set: print … | |
Re: What does restitution in that case mean? Can you give example input and output? | |
Re: You mean, like [this](http://www.wikihow.com/Make-a-Web-Browser) ? :) To develop a webbrowser is as very complex task. Are you sure that this is the task? If yes, I advise you to learn from [others](http://w2spconf.com/2008/papers/s2p2.pdf). Google for webbrowser design. | |
Re: If you remove the duplicates form the linked list: 3,2,8,8,8,5,2,3 then it remains: 3,2,8,5. I do not understand why you expect a list with duplicates. If the Node object is something like this: class Node(object): def __init__(self, value, next=None): self.next=next self.value=value Then removing the duplicates is something like this (the … | |
Re: It works on windows. `python pro.py -u aaa -p Example$319` aaa Example$319 calling program The shell you are using is interpreting your arguments. Try to escape the arguments with apostrophes (depending on the shell you are using). Also the shebang (#!...) line should be int the first line. | |
Re: double underscore in init Several typos. class employee(): empcount=0 def __init__(self,name,salary): self.name=name self.salary=salary employee.empcount+=1 def displaycount(self): print 'Total employee: %d' %employee.empcount def displayemployee(self): print 'Name:',self.name,'salary:',self.salary ######################################################### #main program emp1n=raw_input('enter name of employee1:') emp2n=raw_input('enter name of employee2:') emp1s=input('enter salary of employee1:') emp2s=input('enter salary of employee2:') emp1=employee(emp1n,emp1s) emp2=employee(emp2n,emp2s) emp1.displayemployee() emp2.displayemployee() print 'total … | |
Re: In the sample text you provided there is no "|" charachter. You base your split on it. How and why? I would have written the program for you, if I had found the kjv.txt in the format you mentioned by quick googling. All I found was this: http://www.bibleprotector.com/TEXT-PCE.zip , which … | |
Re: In my experience this is one of a big issues with python. There is no methodology for design. No online resource about how to turn requirements into code skeleton. I think that is because there are rarely big projects (with more than 10 developer at a time), and the few … | |
Re: Not a python question. In general a file is a stream of bytes. You merge two files by reading them one after the another and writing them. fo=open("outfile","wb") fo.write(open("infile1").read()) fo.write(open("infile2").read()) fo.close() Thats the general part of it. However a file is interpreted by a program. A videofile is interpreted by … | |
Re: "EOF" means three letters: E,O,F. This statement is never True: if textInput == "\n" and textInput == "EOF": One way to handle this ("\n" cannot be entered) is to catch EOFError: inputs=list() while True: try: s = input() inputs.append(s) except EOFError: print(inputs) break | |
Re: Maybe you have more python binaries installed. Instead of virtualenv thing use /usr/bin/python2.6 PATH/TO/VIRTUALENV thing Also: http://stackoverflow.com/questions/5904319/problem-with-virtualenv-in-mac-os-x | |
Re: Errors: You define user_inputs as a list, then redefine it as a string. You might have not decided whether you collect all the inputs and then calculate the sum, or you want to calculate it on the fly.. Wrong intendation in the post. You do not use the total variable. … | |
Re: I have once watched a great pycon video about the python execution process. Sadly I cannot find any written words about that. In my understanding it works as follows: * The python interpreter "executes" from the first line of the script. * This execution involves compilation and evaluation. Evaluation is … | |
Re: - The line: segment = f.read(segmentbytes) should be in the "for j in range(numframe)" loop. - Your numframe is not correct. Shoult be +1. |
The End.