761 Posted Topics
Re: How about this: [code] >>> a = [[1,2,3], [4,5,6], [7,8,9]] >>> new_a = [] >>> for each_a in a: ... new_a += each_a ... >>> new_a [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> [/code] | |
Re: In order to see a hyperlink you would need something that was capable of rendering HTML. Why don't you try opening the output from Python in your web browser | |
Re: The backslash (\) is used for an "escape character". So \t is the escape character for a tab, \n is for newline, and \" or ' are escapes for a double and single quote respectively. Let's say we have a string: [icode]'Hi my name is Charlie'[/icode]. The single quotes are … | |
Re: Maybe it's four 8-bit numbers together? [code]>>> i = '100010101001000010000011111001010' >>> first_num = int(i[:8],2) >>> secnd_num = int(i[8:16],2) >>> third_num = int(i[16:24],2) >>> fourt_num = int(i[24:32],2) >>> first_num 138 >>> secnd_num 144 >>> third_num 131 >>> fourt_num 229 >>> [/code] | |
Re: Are you describing a "race condition"? If you are working with something like this you are not a newbie, this is complex stuff. try googling "data race condition" and learn about the different methods to solve this fundamental software design issue. | |
Re: You could do a simple while loop: [code]import subprocess repeat = 'y' while repeat == 'y': subprocess.call(["programname"]) repeat = raw_input("Would you like to run again? (y/n) ")[/code] | |
Re: [QUOTE=slate;1096212]Just for the record. Do not use window path strings as path strings. ... The ways to do this: os.path.join("c:", "Process new","RF","test.dat") [/QUOTE] Slate, Just a minor correction in your example. For some reason on Windows the os.path.join function does not play nice with drive letters. When using a drive … | |
Re: You have a lot of options. If you're looking to purely look at html you can use urllib2, or if you'd rather have the module parse out all the elements for you and give you purely the text data you'd be better off using beautifulsoup. Search this forum to find … | |
Re: It looks like you're using a Python version that is not 3.X ... so in that case you should be using raw_input() instead of input(). raw_input stores the user's input as a string, which is the way input() works in Python 3.0 and up | |
Re: [QUOTE=bryancan;1094201]so if I have the variable: mes = "[ $(date +\%d) -eq $(echo $(cal) | awk {print $NF}) ] && "+buCommand os.popen("echo '"+mes+"'>>/etc/cron.d/"+mycronfile+";") how do I KEPP my single quotes?[/QUOTE] You put them in the mes variable :P Above you have: [code]mes = "[ $(date +\%d) -eq $(echo $(cal) | … | |
Re: This would also likely require that your Python program run in the background as a service. It would need to monitor the presence of a USB flash drive and act accordingly when it detected one. There is information in this forum for setting up a service in Windows if you … | |
Re: [QUOTE=tigrum;1007077] [CODE] c.execute("UPDATE a SET last = %s", row) [/CODE] what is the wrong thing that I am doing here?[/QUOTE] I believe you forgot to replace the comma (,) with a percentage sign (%). Shouldn't the above code be: [CODE=python] c.execute("UPDATE a SET last = %s" % row) [/CODE] ? … | |
Re: Here, [URL="http://www.python.org/dev/peps/pep-0263/"]this should give you some insight[/URL] into how to define an encoding style for your whole python script. | |
Re: You can use either a tk or wxPython file dialog. Both should provide a native file chooser window for the user. Plenty of examples on this site or through searching google. | |
Re: [QUOTE=masterinex;1084981]hey, I tried it with mpaaget = re.compile('<div class="info-content">(.*?)</div>') but then I got something else . Could it be because there is a new line after <div class="info-content"> ? How do I take care of that?[/QUOTE] Yes, the white space does not fit into your regular expression. Modify like so … | |
Re: [QUOTE=curiouskitten;813921]Any corrections and explanations to my code?[/QUOTE] Your return statement is inside your for loop so it's exiting on the first iteration.... if you knock it back an indentation level it'll work: [code=python] >>> def int2roman(number): ... numerals={1:"I", 4:"IV", 5:"V", 9: "IX", 10:"X", 40:"XL", 50:"L", ... 90:"XC", 100:"C", 400:"CD", 500:"D", … | |
Re: Personally I'd use regular expressions like so: [code]>>> import re >>> regex_compiled = re.compile('^<Ranking: (.*) \((.*)\)>$') >>> input_data = """<Ranking: AA (John)> ... <Ranking: CA (Peter)> ... <Ranking: TA-A (Samantha)> ... """ >>> for each_entry in input_data.split('\n'): ... regex_match = regex_compiled.match(each_entry) ... if regex_match: ... print 'Ranking: % 5s Name: … | |
Re: Use code tags, Makes it easier for us to read. Let me explain the code: [B]import[/B] sys [B]print [/B]>> sys.stderr, 'Fatal error: invalid input!' logfile = open('/tmp/mylog.txt', 'a') [B]print[/B] >> logfile, 'Fatal error: invalid input!' logfile.close() 1. We import the sys module [documentation here](http://docs.python.org/library/sys.html#module-sys) 2. We print the message 'Fatal … | |
Re: So you literally take your object and perform a [icode]str(object)[/icode]? And that's what you're trying to turn back into a proper python object? For that you would use a simple eval(): [code]to = ['This is my list', 'With Stuff', [0,1,2,3,4], 'Foo', 112, 5, '57 + 1'] my_saved_ver = str(to) tr … | |
Re: What about something like this (making use of integer division): [CODE]keycode = raw_input() matrix = [0, 0, 0, 0] for x in range(0, len(keycode)): y = ord(keycode[x]) factor = x / 4 x = x - (4 * factor) matrix[x] = matrix[x] + y [/CODE] Not sure if that's what … | |
Re: [QUOTE=rehber344;1079724]ı want to make a loop that wıll change port adress[/QUOTE] Here's a simple loop generating your example output strings between 111 and 115. I'm sure you can figure out how to extend up to 800. [code]>>> for x in xrange(111, 115): ... print '/sbin/iptables -A INPUT -p tcp --dport … | |
Re: [URL="http://chronicgrad.wordpress.com/2009/02/18/getting-scipy-and-numpy-working-on-ubuntu-810/"]This [/URL]was the first google result for "ubuntu python numpy". [quote]sudo apt-get install python-numpy python-scipy Also, don't forget to install matplotlib and its dependent files: sudo apt-get install python-matplotlib python-tk[/quote] Also, the author mentions that the scipy website provides [URL="http://www.scipy.org/Download"]pre-built binaries[/URL] for Ubuntu already. | |
Re: What about passing the class instance as a parameter to your function? | |
Re: Typically when you create a module that you want to use in another script you save it as a file (we'll use my_module.py as an example). Then in your script in which you want to use said module you would do [icode]import my_module[/icode]; however this assumes that my_module is visible … | |
Re: [QUOTE=ffs82defxp;1074130]Okay so returning signals the end of a function as well as confirms the functions ability to pass a variable made in the function?[/QUOTE] Yes, a [icode]return[/icode] statement exits the function and passes a value back to the point in code that called it. You can return any object no … | |
Re: Using a leading double underscore on a class member makes it psuedo-private; however with persistence you can still see/access the object (it's just not immediately apparent). There is no such thing as "private" in Python. [code=python]>>> class A(object): ... _Member_A = 'a' ... __Member_B = 'b' ... >>> dir(A) ['_A__Member_B', … | |
Re: Yes, you could create a general Student class and then go about creating instances of the class. Each instance would represent a different student and would contain the necessary data to individualize and represent the student's details. If you look around this forum you'll find examples of "shapes" and "pets" … | |
Re: I just ran your program verbatim and it ran all the way to the end. How are you running your program? | |
Re: Here's a regular expression that should work for you: [icode]re.split('([.!?] *)', a)[/icode] If you need it broken down and explained for you I can do that; otherwise, it may be more fun to investigate using the documentation and pick it apart to learn how it works! Here's me using your … | |
Re: [QUOTE=paulgerard11;1067263]have code snippet.any ideas? for clust in clusters: #for each name in a list of names i have outNM = "fam" + str(count) + ".mcl.fas" #a series of files i want written to outFL = open(outNM, 'a') for c in clust: #for each letter in my list of names that … | |
Re: Wow, that code is pretty long! Here's a shortened version: [code] import string # Strings are already iterable so we don't need to convert to list message = raw_input('Enter a string: ') # Make a string of a space plus all the lower case letters (the first ## 26 indices … | |
Re: [QUOTE=Kruptein;1066027]If I start my program and choose to show the option frame, it will show it, but if I now close both frames the program keeps running in the background..[/QUOTE] It would be helpful if you showed us the relative code (ie, how you're opening the Optionframe and how you're … | |
Re: [QUOTE=Vector_Joe;1064026]where can I find a reference for what the different parts of the command means. Anyone know where I can find this information for these an similar commands?[/QUOTE] [URL="http://docs.activestate.com/komodo/5.0/shortcuts.html#shortcuts_all_codes"]This[/URL] was found through the tutorials section on the Komodo Edit project hosted on active-state. | |
Re: [QUOTE=roshini.johri;1058316]i am having diff in understanding this code..i am supp to do it in python[code] for qid,query in "as2.qrys": for word in query: docs = set(index[word]) for doc in docs: number_of_matched_words [doc] ++ for doc in matches: if number_of_matched_words[doc] == length(query): print qid, 0, doc, 0, 1, 0 [/code][/QUOTE] Is … | |
Re: It's hard to tell whether you did this or not since you didn't give us all your code, but I'm assuming that before assigning to Templng you used [icode]global Templng[/icode] to let the local scope know you meant to use the global variable and not just create a new local … | |
Re: [QUOTE=Archenemie;1056435]28 Minutes Ago | Add Reputation Comment | Flag Bad Post [/QUOTE] Hah, that's awesome... [QUOTE=Archenemie;1056435]One last problem with my script, it returns this error message... [CODE]Traceback (most recent call last): File "C:/Python26/Renamer 3", line 23, in <module> os.rename(fname, b)WindowsError: [Error 2] The system cannot find the file specified.Traceback (most … | |
Re: [QUOTE=gregsmith01748;1056350]If you want to use backslashes in a path name for loadtxt (or savetxt), the you need to put in double backsplashes so: 'c:/users/ross/desktop/radiograph_data.txt' becomes: 'c://users//ross//desktop//radiograph_data.txt'[/QUOTE] Those are forward slashes, which do not need to be escaped (the escape character is \, which is backslash) | |
| |
Re: [QUOTE=mahela007;1052481]How do I call the program from the command line?[/QUOTE] Type your python command (*if you haven't set it up you'll need to use the full pathname to python.exe or pythonw.exe), then the name of your script, then the command line arguments... here's an example: [quote]Microsoft Windows XP [Version 5.1.2600] … | |
Re: [QUOTE=ov3rcl0ck;1052480]Can you give me an example?[/QUOTE] Better yet: I'll give you about [URL="http://tinyurl.com/ydd96ld"]57,900 examples[/URL] | |
Re: Welcome to the forums. EDIT: OP Updated post with Code tags Also, when asking about a specific error you get, it would help if we could see the entire traceback (which helps to identify exactly what line the error occured on). Seeing as you have an indexing error, we can … | |
Re: [QUOTE=mahela007;1051500]The tkinter tutorial at tkdocs ([url]http://www.tkdocs.com/tutorial/firstexample.html[/url]) shows these two lines at the beginning of every example. [CODE]from tkinter import * from tkinter import ttk[/CODE] Doesn't the first line import everything in the tkinter module? if so, why bother writing the second line?[/QUOTE] When performing an [ICODE]import *[/ICODE] in Python, you … | |
Re: You have a number of issues in your code revolving around scope. Here are the first few that jumped out at me: 1) In your dig_sum function, you refer to i but never define it (in your while loop). Perhaps you're referring to the i from the avo function or … | |
Re: [QUOTE=krishna_sicsr;1046890]Hi, While running my Python Script I am getting "org.python.core.PyInstance" ERROR. I am not getting why this ERROR is coming. Please help......[/QUOTE] With the limited information that you've provided my only guess would be that your Python installation is corrupted. You should reinstall. | |
Re: When you return an object it isn't just automagically added to the current namespace... you need to actually store it in something. All you'll need to do is say [icode]graph = plot_it(...)[/icode], savvy? | |
![]() | Re: [QUOTE=leegeorg07;1046420] [code] for i in range(len(dict)): dict[i] = dict[i][0:len(dict[i])-2][/code][/QUOTE] What is that? What are you doing? EDIT: Also remember that dict is a reserved word in Python I suggest that you change the name ![]() |
Re: [QUOTE=masterofpuppets;1046421]wow thanks for that dude I was actually wondering how to create private variables in Python. That really helped :)[/QUOTE] Yes, but be forewarned it's psuedo-private. You can still see and access the variable, it's just obfuscated with the Class name. Look: [code=python]>>> class Cpriv(object): ... def __init__(self): ... self.__privy … | |
Re: [QUOTE=sanchitgarg;1046475]suppose i have 10 different functions. i generate a random no. between 1 to 10. depending on its value i want to call the fucntion. eg. no. 3 call func, no. 8 calls func 8... etc. how do i do it using a loop without using the if else statement … | |
Re: My first suggestion is to remove the giant try/except block. If you make a syntax error your program will quit and never tell you the reason why. That is extremely poor Python coding and opens the door for you to create debilitating issues in your code. Now, in order to … |
The End.