Search Results

Search found 19539 results on 782 pages for 'pretty print'.

Page 147/782 | < Previous Page | 143 144 145 146 147 148 149 150 151 152 153 154  | Next Page >

  • Python:How to override inner class methods if the inner class is defined as a property of the top cl

    - by Maddy
    I have a code snippet like this class A(object): class b: def print_hello(self): print "Hello world" b = property(b) And I want to override the inner class 'b'(please dont worry about the lowercase name) behaviour. Say, I want to add a new method or I want to change an existing method, like: class C(A): class b(A.b): def print_hello(self): print "Inner Class: Hello world" b = property(b) Now if I create C's object as c = C(), and call c.b I get TypeError: 'property' object is not callable error. How would I get pass this and call print_hello of the extended inner class? Disclaimer: I dont want to change the code for A class.

    Read the article

  • Why does my regex fail when the number ends in 0?

    - by Russell C.
    This is a really basic regex question but since I can't seem to figure out why the match is failing in certain circumstances I figured I'd post it to see if anyone else can point out what I'm missing. I'm trying to pull out the 2 sets of digits from strings of the form: 12309123098_102938120938120938 1321312_103810312032123 123123123_10983094854905490 38293827_1293120938129308 I'm using the following code to process each string: if($string && $string =~ /^(\d)+_(\d)+$/) { if(IsInteger($1) && IsInteger($2)) { print "success ('$1','$2')"; } else { print "fail"; } } Where the IsInterger() function is as follows: sub IsInteger { my $integer = shift; if($integer && $integer =~ /^\d+$/) { return 1; } return; } This function seems to work most of the time but fails on the following for some reason: 1287123437_1268098784380 1287123437_1267589971660 Any ideas on why these fail while others succeed? Thanks in advance for your help!

    Read the article

  • How to use avg function?

    - by Marcelo
    I'm new at php and mysql stuff and i'm trying to use an avg function but i don't know how to. I'm trying to do something like this: mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die ("Did not connect to $database"); mysql_query("AVG(column1) FROM table1 ") or die(mysql_error()); mysql_close(); echo AVG(column1); (Q1)I'd like to see the value printed in the screen, but i'm getting nothing but an error message. How could I print this average on the screen ? (Q2)If I had a column month in my table1, how could I print the averages by the months ? Sorry for any bad English, and thanks for the attention.

    Read the article

  • Python scope problems only when _assigning_ to a variable

    - by wallacoloo
    So I'm having a very strange error right now. I found where it happens, and here's the simplest code that can reproduce it. def parse_ops(str_in): c_type = "operator" def c_dat_check_type(t): print c_type #c_type = t c_dat_check_type("number") >>> parse_ops("12+a*2.5") If you run it as-is, it prints "operator". But if you uncomment that line, it gives an error: Traceback (most recent call last): File "<pyshell#212>", line 1, in <module> parse_ops("12+a*2.5") File "<pyshell#211>", line 7, in parse_ops c_dat_check_type("number") File "<pyshell#211>", line 4, in c_dat_check_type print c_type UnboundLocalError: local variable 'c_type' referenced before assignment Notice the error occurs on the line that worked just fine before. Any ideas what causes this and how I can fix this? I'm using Python 2.6.1.

    Read the article

  • find whether the string starts and ends with the same word

    - by Ajax
    I am trying to check whether the string starts and ends with the same word. egearth. s=raw_input(); m=re.search(r"^(earth).*(earth)$",s) if m is not None: print "found" my problem is when the string consists only of one word eg: earth At present I have hard coded this case by if m is not None or s=='earth': print "found" Is there any other way to do this? EDIT: words in a string are separated by spaces. looking for a regex solution some examples: "earth is earth" ,"earth", -- valid "earthearth", "eartheeearth", "earth earth mars" -- invalid

    Read the article

  • Storing cvs data for further manipulation using Ruby

    - by ischnura
    I am dealing with a csv file that has some customer information (email, name, address, amount, [shopping_list: item 1, item 2]). I would like work with the data and produce some labels for printing... as well as to gather some extra information (total amounts, total items 1...) My main concern is to find the appropriate structure to store the data in ruby for future manipulation. For now I have thought about the following possibilities: multidimensional arrays: pretty simple to build, but pretty hard to access the data in a beautiful ruby way. hashes: having the email as key, and storing the information in different hashes (one hash for name, another hash for address, another hash for shopping list...) (getting the cvs data in to a Database and working with the data from ruby??) I would really appreciate your advice and guidance!!

    Read the article

  • how to merge file lines having the same first word in python?

    - by user1377135
    I have written a program to merge lines in a file containing the same first word in python. However I am unable to get the desired output. Can anyone please suggest me the mistake in my program? input "file.txt" line1: a b c line2: a b1 c1 line3: d e f line4: i j k line5: i s t line6: i m n ` output a b c a b1 c1 d e f i j k i s t i m n my code a = [line.split() for line in open('file.txt')] L=[] for i in range(0,len(a)): j=i while True: if a[j][0] == a[j+1][0]: L.append(a[j]) L.append(a[j+1]) j=j+2 else: print a[i] print L break

    Read the article

  • C segmentation fault before/during return statement

    - by wolfPack88
    I print the value that I'm returning right before my return statement, and tell my code to print the value that was returned right after the function call. However, I get a segmentation fault after my first print statement and before my second (also interesting to note, this always happens on the third time the function is called; never the first or the second, never fourth or later). I tried printing out all of the data that I'm working on to see if the rest of my code was doing something it maybe shouldn't, but my data up to that point looks fine. Here's the function: int findHydrogen(struct Amino* amino, int nPos, float* diff, int totRead) { struct Atom* atoms; int* bonds; int numBonds; int i; int retVal; int numAtoms; numAtoms = (*amino).numAtoms; atoms = (struct Atom *) malloc(sizeof(struct Atom) * numAtoms); atoms = (*amino).atoms; numBonds = atoms[nPos].numBonds; bonds = (int *) malloc(sizeof(int) * numBonds); bonds = atoms[nPos].bonds; for(i = 0; i < (*amino).numAtoms; i++) printf("ATOM\t\t%d %s\t0001\t%f\t%f\t%f\n", i + 1, atoms[i].type, atoms[i].x, atoms[i].y, atoms[i].z); for(i = 0; i < numBonds; i++) if(atoms[bonds[i] - totRead].type[0] == 'H') { diff[0] = atoms[bonds[i] - totRead].x - atoms[nPos].x; diff[1] = atoms[bonds[i] - totRead].y - atoms[nPos].y; diff[2] = atoms[bonds[i] - totRead].z - atoms[nPos].z; retVal = bonds[i] - totRead; bonds = (int *) malloc(sizeof(int)); free(bonds); atoms = (struct Atom *) malloc(sizeof(struct Atom)); free(atoms); printf("2 %d\n", retVal); return retVal; } } As I mentioned before, it works fine the first two times I run it, the third time it prints the correct value of retVal, then seg faults somewhere before it gets to where I called the function, which I do as: hPos = findHydrogen((&aminoAcid[i]), nPos, diff, totRead); printf("%d\n", hPos);

    Read the article

  • why is this dictionary line number count not working?

    - by jad
    i have this piece of code the last bit of the code starting from d = {} im trying to print the words with its line number located in the text but it is not working its only printing the words anyone know why ??? need help ASAP import sys import string text = [] infile = open(sys.argv[1], 'r').read() for punct in string.punctuation: infile = infile.replace(punct, "") text = infile.split() dict = open(sys.argv[2], 'r').read() dictset = [] dictset = dict.split() words = [] words = list(set(text) - set(dictset)) words = [text.lower() for text in words] words.sort() d = {} counter = 0 for lines in text: counter += 1 if word not in d: d[words] = [counter] else: d[words.append[counter] print(word, d)

    Read the article

  • Django - Empty session data in ajax requests

    - by ninja123
    Hi guys, I have an ajax view where I want to set a session variable like such: def upload(request, *args, **kwargs): request.session['test'] = 'test' request.session.modified = True print request.session.items() I have another normal view something like this: def advertise(request): print request.session.items() I get these two strings printed to shell: [('test', 'test')] [('_auth_user_backend', 'django.contrib.auth.backends.ModelBackend'), ('_auth_user_id', 26L)] Why is the session data that I set in the ajax view not passing to my regular views? If I set session data in regular view, everything works as fine, but it seems that ajax requests contain empty session data? Anybody dealt with something like this before? Any suggestions are greatly appreciated. Thanks.

    Read the article

  • How to convert list into a string?

    - by PARIJAT
    I have extracted some data from the file and want to write it in the file 2 but the program says 'sequence item 1: expected string, list found', I want to know how I can convert buffer[] i.e. string into sequence, so that it could be saved in file 2. file = open('/ddfs/user/data/k/ktrip_01/hmm.txt','r') file2 = open('/ddfs/user/data/k/ktrip_01/hmm_write.txt','w') buffer = [] rec = file.readlines() for line in rec : field = line.split() print '>',field[0] term = field[0] buffer.append(term) print field[1], field[2], field[6], field[12] term1 = field [1] buffer.append(term1) term2 = field[2] buffer.append[term2] term3 = field[6] buffer.append[term3] term4 = field[12] buffer.append[term4] file2.write(buffer) file.close() file2.close()

    Read the article

  • Grabbing Data From Controls In Code Behind

    - by MKell43
    Hopefully this is a pretty simple question for someone to answer. I have a drop down list control that I need to pull the value from in the code behind of the page, modify it and redisplay it. The modifying and redisplaying I've got no problem with, it's grabing the value from the drop down control. Examples in C# would be appreciated as this web app I've been handed is already coded that way. I'm pretty new to .Net so be gentle and I already did some searching via Google and a little bit on the site here, but couldn't find anything that stood out as being the direction to go in to do this.

    Read the article

  • How to call a specific, unknown Python object attribute?

    - by Michael Morisy
    I'm working to create a simple Python script that will ultimately tell you how many blog entries were posted in a given month, and the pyblog app is proving very helpful. However, when I create the blog object, I don't know how to access it's various attributes. I can print them all out by printing one item from the dictionary, as shown (in excerpts) below: print blog.get_recent_posts(1) 'post_status': 'publish', 'date_created_gmt': <DateTime '20100601T19:27:17' at 2853300>, 'mt_excerpt': '', 'userid': '288', 'dateCreated': <DateTime '20100601T14:27:17' at 2853350>, 'custom_fields': [{'value': '', 'id': '1317', 'key': 'brightcove_code'}, {'value': 'http://bit.ly/d0Rywl', 'id': '1403', But how can I just get it to provide that DateTime information?

    Read the article

  • Google Social Graph API, working as intended?

    - by pns
    Hey, I'm experiencing some problems with Google's social graph API. It seems that for some parameters passed to 'otherme' nothing is returned. I'll use Robert Scoble's profiles as an example (as he's a guy sure to be everywhere on the web). If I query: http://socialgraph.apis.google.com/otherme?q=http://twitter.com/scobleizer&pretty=1 I get results, as expected. However, if I query: http://socialgraph.apis.google.com/otherme?q=http://delicious.com/scobleizer&pretty=1 Nothing is returned, even though 'http://delicious.com/scobleizer' is listed in the previous results... Any thoughts? Thanks

    Read the article

  • .pl or .cgi for perl web script file,which one is more popular?

    - by Nano HE
    HI. I created two files 'hello.pl' and 'hello.cgi' with the code below. #!/usr/bin/perl print "Content-type:text/html\n\n"; print "hello world"; I can view the page via both http://www.mydomain.com/cgi-bin/hello.pl and http://www.mydomain.com/cgi-bin/hello.cgi. Which one is more sense in Perl web dev? BTW, the directory of 'cgi-bin' created by my VPS server, Do I need contact with my VPS support to remove it or just remain it like this URL style? Maybe http://www.mydomain.com/perDev/hello.cgi is better?

    Read the article

  • SSRS mysterious extra pages

    I have two reports that are setup with the same page dimensions- A4 portrait, with page margins of 1cm. When I run the reports seperately and print them they both come out as expected: fitting into the width constraint of the page. However, when I include one report as a subreport in the other and then run and print the "master" report I start to experience problems. Even though both reports appear I get extra blank pages appearing every other page in the output. I'm sure I'm missing a simple trick - probably with the page sizes of the two reports but I can't figure it out - any pointers? I don't mind changing the setup of the subreport as it will never be run as a seperate eport in the wild, I only included that step to prove that it did indeed fit within the page!

    Read the article

  • Python script run via cron does not execute occassionally

    - by gcorne
    I have a simple python script for fetching tweets and caching them to disk that is configured to run every two minutes via cron. */2 * * * * (date ; /usr/bin/python /path/get_tweets.py) >> /path/log/get_tweets.log 2>&1 The script runs successfully most of the time. However, every so often the script doesn't execute. In addition to other logging, I added a simple print statement above the meat of the script and nothing except the output from the initial date command makes it to the log. #!/usr/bin/python # Script for fetching tweets and then storing them as an HTML snippet for inclusion using SSI print "Starting get_tweets.py" Any ideas? The system is a VPS running Centos 5.3 with python 2.4.

    Read the article

  • Shift operator in Java bizarre program output

    - by Umesh Kacha
    I came across the following program and it behaving in unexpected manner. public class ShiftProgram { public static void main(String[] args) { int i = 0; while(-1 << i != 0) i++; System.out.println(i); } } If we think about this program output, when it reaches 32 while loop condition should return false and terminate and it should print 32. If you ran this program, it does not print anything but goes into an infinite loop. Any idea whats going on? Thank you in advance.

    Read the article

  • Printing UTF-16 strings in JSP is outputted as HTML encoding (&#xxxx)

    - by Ori Osherov
    Hello, When I try to print a UTF-16 string in JSP, specifically Hebrew, it ends up showing up as HTML encoding (&#xxxx). This problem occurs because I print an array of variables into the web page and then parse them. The variables are all UTF-16 strings, but once the servlet prints the variables, it becomes translated to HTML encoding. Is there any way to get rid of the encoding? Thanks in advance Edit for a bit more background: The JSP that I'm printing is not the entirety of the page. It's used in a manner I don't quite understand by a server app which prints the JSPs output into its built in page. As a result, I can't, for instance, use a tag because the will have already been placed somewhere else. This isn't a frame or anything like that. It's just redirected output.

    Read the article

  • PHP & MySQL Undefined variable problem

    - by comma
    I keep getting the following error Undefined variable: id on line 91 can some one help me correct this problem? The error is on this line. $query2 = "INSERT INTO users_skills (skill_id, user_id, date_created) VALUES ('$id', '$user_id', NOW())"; MySQL database tables. CREATE TABLE tags ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, skill VARCHAR(255) NOT NULL, experience VARCHAR(255) NOT NULL, years VARCHAR(255) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE users_skills ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, skill_id INT UNSIGNED NOT NULL, user_id INT UNSIGNED NOT NULL, date_created DATETIME UNSIGNED NOT NULL, PRIMARY KEY (id) ); Here is the PHP & MySQL code. if (isset($_POST['info_submitted'])) { $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $dbc = mysqli_query($mysqli,"SELECT learned_skills.*, users_skills.* FROM learned_skills INNER JOIN users_skills ON learned_skills.id = users_skills.skill_id WHERE user_id='$user_id'"); if (!$dbc) { print mysqli_error($mysqli); return; } $user_id = '5'; $skill = $_POST['skill']; $experience = $_POST['experience']; $years = $_POST['years']; $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $dbc = mysqli_query($mysqli,"SELECT learned_skills.*, users_skills.* FROM learned_skills INNER JOIN users_skills ON users_skills.skill_id = learned_skills.id WHERE users_skills.user_id='$user_id'"); if (mysqli_num_rows($dbc) == 0) { if (isset($_POST['skill']) && trim($_POST['skill'])!=='') { $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $query1 = mysqli_query($mysqli,"INSERT INTO learned_skills (skill, experience, years) VALUES ('" . $skill . "', '" . $experience . "', '" . $years . "')"); if (mysqli_query($mysqli, $query1)) { print mysqli_error($mysqli); return; } $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $dbc = mysqli_query($mysqli,"SELECT id FROM learned_skills WHERE id='" . $skill . "' AND experience='" . $experience . "' AND years='" . $years . "'"); if (!$dbc) { print mysqli_error($mysqli); } else { while($row = mysqli_fetch_array($dbc)){ $id = $row["id"]; } } $query2 = "INSERT INTO users_skills (skill_id, user_id, date_created) VALUES ('$id', '$user_id', NOW())"; } }

    Read the article

  • Find the min max and average of one column of data in python

    - by user1440194
    I have a set of data that looks like this 201206040210 -3461.00000000 -8134.00000000 -4514.00000000 -4394.00000000 0 201206040211 -3580.00000000 -7967.00000000 -4614.00000000 -7876.00000000 0 201206040212 -3031.00000000 -9989.00000000 -9989.00000000 -3419.00000000 0 201206040213 -1199.00000000 -6961.00000000 -3798.00000000 -5822.00000000 0 201206040214 -2940.00000000 -5524.00000000 -5492.00000000 -3394.00000000 0 I want to take the second to last column and find the min, max, and average. Im a little confused on how to use split when the columns are delimited by a space and -. i Figure once i do that i can use min() and max function. I have written a shell script to do the same here #!/bin/ksh awk '{print substr($5,2);}' data' > /data1 sort -n data1 > data2 tail -1 data2 head -1 data2 awk '{sum+=$1} END {print "average = ",sum/NR}' data2 Im just not sure how to do this in python. Thanks

    Read the article

  • How do I splice a python string programmatically?

    - by Robin Welch
    Very simple question, hopefully. So, in Python you can split up strings using indices as follows: >>> a="abcdefg" >>> print a[2:4] cd but how do you do this if the indices are based on variables? E.g. >>> j=2 >>> h=4 >>> print a[j,h] Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: string indices must be integers

    Read the article

  • Decoding utf16 in Perl?

    - by Geo
    If I open a file ( and specify an encoding directly ) : open(my $file,"<:encoding(UTF-16)","some.file") || die "error $!\n"; while(<$file>) { print "$_\n"; } close($file); I can read the file contents nicely. However, if I do: use Encode; open(my $file,"some.file") || die "error $!\n"; while(<$file>) { print decode("UTF-16",$_); } close($file); I get the following error: UTF-16:Unrecognised BOM d at F:/Perl/lib/Encode.pm line 174 How can I make it work with decode?

    Read the article

  • Blank Swf after printing from another app.

    - by Carlos Barbosa
    Ok, so i am having a problem, where i developed an app that uses the webcam, adds an image and then takes a picture, well, i implemented textbook style the printjob, and well everytime after printing my swf goes blank. http://stackoverflow.com/questions/3021557/as3-printing-problem-blanks-swf-after-print-or-cancel But now i have been continuing testing, and i found out, that if i print from another application and then comeback, my video stream from the webcam is blank, this has no sense at all, since i am printing from another app. Please i need help with this, i have found one additional case: http://board.flashkit.com/board/showthread.php?t=781089 What is going on here i mean, this must be a flash player issue right.

    Read the article

< Previous Page | 143 144 145 146 147 148 149 150 151 152 153 154  | Next Page >