15,185 Topics

Member Avatar for
Member Avatar for KY_Fan

This class just keeps getting worse. My next lab he had us do is this, **"Write a program that computes the intersection of a circle with a horizontal line and displays the information textually and graphically".** He gave us absolutely no help or anything to do this. He just said …

Member Avatar for KY_Fan
0
420
Member Avatar for hughesadam_87

Hi, If I have a list of strings, it's easy to output them using .join(). For example: mylist=['hi', 'there', 'girls'] myout='\t'.join(mylist) What I want to know is if there is a builtin python method that acts like join, except it automatically converts ints and floats to strings without giving a …

Member Avatar for TrustyTony
0
120
Member Avatar for 4evrmrepylrning

I have this: import re subs = [] def subcons(data): match = re.search(r'(<[a-z]{3})', data) if match: subs.append(match.group(0)) data = data.replace(match.group(0), '') subcons(data) else: print data return data, subs input = 'ABC <uvw <xyz some random data' e, f = subcons(input) print e print f The print statement in the else …

Member Avatar for TrustyTony
0
211
Member Avatar for TrustyTony

Do you get content of oper right before trying it out? oper = ['plus', 'minus', 'times'] oper.extend('divide') How about do you know what happens when you run this? Big bang? ;) print('a' 'b' 'c') And this is same, isn't it`? c = 'c' print('a' 'b' c)

Member Avatar for snippsat
1
183
Member Avatar for chophouse

This is part of another script, too long for here, but isolating this part, my dilemma is that this works when manually invoked from IDLE, but not when run as a cron job. from datetime import datetime import os # check to see if a log file exists, make one …

Member Avatar for chophouse
0
236
Member Avatar for TrustyTony

Here you see how one could use recursion together with generators for (inefficient) permutations generator. It is kind of interesting to know how one can do it recursively (of course there exist many ways). Anyway this snippet demonstrates how you can use recursive generator call to feed a for statement. …

0
432
Member Avatar for prashanthmukund

I am a newbie to python. I am just working on a program to count number of letters in each words of a sentence. That includes punctuation too. If the sentence is "This is it!" my program should give "4 2 3". First I thought I can convert this string …

Member Avatar for Lucaci Andrew
0
394
Member Avatar for hisan

below is mycode though i have set keepalive, socket connection gets closed after sometime. sb_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,socket.SOL_TCP) sb_sock.setsockopt( socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) sb_sock.connect((msg_host, host_port)) reg_msg="REG 0000 "+finder_id+"\r" sb_sock.send(reg_msg)

Member Avatar for hisan
0
516
Member Avatar for TrustyTony

I googled little around for correct way to not reinventing of the wheel for expression evaluation (even I had done some simple evaluation check for my [Tkinter calculator snippet](http://www.daniweb.com/software-development/python/code/282548/simple-calculator) earlier). After getting totally upset with [this example](http://www.bestcode.com/html/evaluate_math_expressions_pyth.html), I made this with some struggles with `__builtins__` globals parameter of eval. First …

0
641
Member Avatar for TrustyTony

I am trying to write safyfied evaluator class, and get unexpected `__builtins__` added to dictionary after evaluation. Can somebody explain why/how it happens? import math def echo(n): print n return n def nothing(n): return n debug = nothing class MathParser(object): ''' Mathematical Expression Evaluator class. call evaluate() function that will …

Member Avatar for HiHe
0
301
Member Avatar for deepthought

Hi ALL, I am completely new to python and when i was playing with a while loop in the Python SHELL the code works but when I then put it into a file and saved and then tried to run it I got the error "NameError: name 'b' is not …

Member Avatar for deepthought
0
8K
Member Avatar for Lucaci Andrew

Inspired by some C and C++ threads regarding finding a specific pattern in a file.

Member Avatar for TrustyTony
0
319
Member Avatar for Gribouillis

When working whith large data files, it may be desirable to output a sequence of bytes by large chunks. This snippet defines a file adapter class to handle this transparently. Writing bytes to an ChunkedOutputFile will automatically write the underlying file object by fixed length chunks.

Member Avatar for Gribouillis
3
4K
Member Avatar for reddsoxy

I am self teaching myself python and I have hit a question that I can't seem to figure out dealing with raw_input. This is the code that is confusing me: print "How tall are you?", height = raw_input() print "So, you're %r tall ." % (height) I input my height …

Member Avatar for reddsoxy
1
183
Member Avatar for G_S

Hello, I need your help with something (again): I need to control two text widgets with one scrollbar and, thanks to this website, I found some code to do it using listboxes (here: [url]http://www.daniweb.com/forums/post940371.html#post940371[/url]). I modified it, and it now works with text widgets and pyton 2.x. The problem is: …

Member Avatar for TrustyTony
0
3K
Member Avatar for dwhite12

>I need to take a list of files and remove a '.2' from a line in each file. I then need to rewrite the file without the '.2'. Using the code below I am >able to take a single file and do exactly what i need to but when trying …

Member Avatar for Lucaci Andrew
0
247
Member Avatar for G_S

Hello everybody. I want to make sure about something: If I install ActivePython 3.2 as root on Linux, will it delete the distro's default Python (2.6)? I also installed Python 3.1 a long time ago, so I have Distro's Python 2.6, the official Python 3.1 and want to add this …

Member Avatar for G_S
0
176
Member Avatar for G_S

Hello again. Here are the details: * My litle scripts work perfectly in my virtual Windows XP (I'm using virtualbox if that matters) as long as they are non-compiled .py or .pyw files * After compiling them, I double click on them and a DOS window comes out, then dissapears …

Member Avatar for G_S
0
764
Member Avatar for G_S

Hello. I am trying to create a module containing many little functions useful for linguistics. So far everything works right, but I have a question: is it a problem if a function within a module calls another function within the same module? I mean, I have a function that performs …

Member Avatar for G_S
0
155
Member Avatar for G_S

Hi, this is, let's say, the second part of this thread: [url]http://www.daniweb.com/forums/thread291657.html[/url] I have managed to control two widgets with one scrollbar, but now I have realized that, althought the widgets can be controlled individually via the mouse wheel or the keyboard, I sometimes need individual controls for each widget. …

Member Avatar for G_S
0
286
Member Avatar for hisan

sample_json1={{ "globalControlId": 72, "value": 0, "controlId": 2 }, { "globalControlId": 77, "value": 3, "controlId": 7 } } sample_json2={ { "globalControlId": 77, "value": 3, "controlId": 7 }, { "globalControlId": 72, "value": 0, "controlId": 2 } }

Member Avatar for Schol-R-LEA
0
115
Member Avatar for tunisia

Trying to convert the following block of perl to python for($row = 0, $mytype = 500; $row < $filearray_count; $row++) { if ($_ eq $filearray[$row][0]) { $mytype = $filearray[$row][1]; print "$row, $mytype, $_ \n"; break; And here is the python attempt. I'm not sure if I'm dealing with $mytype = …

Member Avatar for TrustyTony
0
212
Member Avatar for johnadamson

**PLEASE HELP ASAP!!! I need help completing this by tomorrow afternoon!!! Can anybody write this for me???????? ** Chemin de Fer is a French card game. You will be creating a simulation of this card game. In Chemin de Fer, cards have the following values: aces are worth 1, cards …

Member Avatar for Schol-R-LEA
0
478
Member Avatar for Myrna90

Hi, I'm new to python, although I have experience with other programming languages. I installed python and downloaded packages, which all work fine. But now I downloaded Obspy, and it can't find the modules. For example, if I type: from obspy.core import read, it gives an error stating that there …

Member Avatar for Myrna90
0
234
Member Avatar for mozart_azul

Hello! I am new to Python, and I want to learn it. I have just installed Python 2.7.3 And Visual Python Tkinter IDE for Ver 2.6-2.7-3.1 (BETA) –Version: 2.0.12.2524. I was looking into some the Tutorial and follow the first example to code. Here begun my issues. First Step: I …

Member Avatar for mozart_azul
0
919
Member Avatar for auto_1

I'm new to python, so kindly bare with me my query is that how can we get the static strings from the dialog boxes of windows and paste those strings to a notepad or a clipboard file. e.g. if a take the Run Dialog box of Windows all the Strings …

Member Avatar for TrustyTony
0
218
Member Avatar for kace91

Hello to everyone! This is my first post here, I hope you can help me. I'm making a class work in python and I'm a little lost: I have to use classes to represent monomials and polynomials, and the classes should contain methods to add, substract, multiply and divide them. …

Member Avatar for TrustyTony
0
2K
Member Avatar for vertster123

I made a program that outputs a large amount of individual data files that I want to create images for. I created a python script that loops through all of the files, but for some odd reason it crashes after doing 17 images. It is always 17 images, and the …

0
81
Member Avatar for TrustyTony

Sometimes we want to tackle some problem specifying properties of sequence of numbers consisting the integer. Then it is usefull to have function to join many integers to make a long integer. Most efficient way for tight loops is to stay in integers domain and not go through the string …

Member Avatar for TrustyTony
0
295
Member Avatar for TrustyTony

Finding efficiently primes, whose begining numbers are also primes. See the thread http://www.daniweb.com/software-development/cpp/threads/425821/prime-number-c in C++ forum for discussion on topic.

1
271

The End.