Search Results

Search found 8942 results on 358 pages for 'print r'.

Page 133/358 | < Previous Page | 129 130 131 132 133 134 135 136 137 138 139 140  | Next Page >

  • How do I split Chinese characters one by one?

    - by Nano HE
    If there is no special character(such as white space, : etc) between firstname and lastname. Then how to split the Chinese characters below. use strict; use warnings; use Data::Dumper; my $fh = \*DATA; my $fname; # ??; my $lname; # ? ; while(my $name = <$fh>) { $name =~ ??? ; print $fname"/n"; print $lname; } __DATA__ ??? Output ?? ?

    Read the article

  • Removing Item From List - during iteration - what's wrong with this idiom ?

    - by monojohnny
    As an experiment, I did this: letters=['a','b','c','d','e','f','g','h','i','j','k','l'] for i in letters: letters.remove(i) print letters The last print shows that not all items were removed ? (every other was). IDLE 2.6.2 >>> ================================ RESTART ================================ >>> ['b', 'd', 'f', 'h', 'j', 'l'] >>> What's the explanation for this ? How it could this be re-written to remove every item ?

    Read the article

  • Compilation Error related

    - by aparna
    Given: 11. public static void test(String str) { 12. int check = 4; 13. if (check = str.length()) { 14. System.out.print(str.charAt(check -= 1) +", "); 15. } else { 16. System.out.print(str.charAt(0) + ", "); 17. } 18. } and the invocation: 21. test("four"); 22. test("tee"); 23. test("to"); What is the result? A. r, t, t, B. r, e, o, C. Compilation fails. D. An exception is thrown at runtime. Answer: C Can you explain why the compilation fails please?

    Read the article

  • Debugging (displaying) SQL command sent to the db by SQLAlchemy

    - by morpheous
    I have an ORM class called Person, which wraps around a person table: After setting up the connection to the db etc, I run the ff statement. people = session.query(Person).all() The person table does not contain any data (as yet), so when I print the variable people, I get an empty list. I renamed the table referred to in my ORM class People, to people_foo (which does not exist). I then run the script again. I was surprised that no exception was thrown when attempting to access a table that does not exist. I therefore have the following 2 questions: How may I setup SQLAlchemy so that it propagates db errors back to the script? How may I view (i.e. print) the SQL that is being sent to the db engine If it helps, I am using PostgreSQL as the db

    Read the article

  • String loops in Python

    - by Steve Hunter
    I have two pools of strings and I would like to do a loop over both. For example, if I want to put two labeled apples in one plate I'll write: basket1 = ['apple#1', 'apple#2', 'apple#3', 'apple#4'] for fruit1 in basket1: basket2 = ['apple#1', 'apple#2', 'apple#3', 'apple#4'] for fruit2 in basket2: if fruit1 == fruit2: print 'Oops!' else: print "New Plate = %s and %s" % (fruit1, fruit2) However, I don't want order to matter -- for example I am considering apple#1-apple#2 equivalent to apple#2-apple#1. What's the easiest way to code this? I'm thinking about making a counter in the second loop to track the second basket and not starting from the point-zero in the second loop every time.

    Read the article

  • Replacing emty csv column values with a zero

    - by homerjay
    Hey, So I'm dealing with a csv file that has missing values. What I want my script to is: #!/usr/bin/python import csv import sys #1. Place each record of a file in a list. #2. Iterate thru each element of the list and get its length. #3. If the length is less than one replace with value x. reader = csv.reader(open(sys.argv[1], "rb")) for row in reader: for x in row[:]: if len(x)< 1: x = 0 print x print row Here is an example of data, I trying it on, ideally it should work on any column lenghth Before: actnum,col2,col4 xxxxx , , xxxxx , 845 , xxxxx , ,545 After actnum,col2,col4 xxxxx , 0 , 0 xxxxx , 845, 0 xxxxx , 0 ,545 Any guidance would be appreciated

    Read the article

  • What is the difference between panic and an assert?

    - by acidzombie24
    Go doesn't provide assertions. They are undeniably convenient, but our experience has been that programmers use them as a crutch to avoid thinking about proper error handling and reporting. However it has print and println which does panic like print, aborts execution after printing panicln like println, aborts execution after printing Isnt that the same thing as an assert? Why would they claim the above but have panic? i can see it leading to the same problems but adding an error msg to the end of it which can easily be abused. Am i missing something?

    Read the article

  • Why are my \n not working in PHP?

    - by Strawberry
    I'm playing with SAX and noticed it's not line breaking properly. I have no iea why. function flush_data() { global $level, $char_data; $char_data = trim($char_data); if( strlen( $char_data ) > 0 ) { print "\n"; $data = split("\n", wordwrap($char_data, 76 - ($level*2))); foreach($data as $line) { print str_repeat(' ', ($level +1)) . "[".$line."]"."\n"; } } $char_data = ''; }

    Read the article

  • Pointer to struct, containing pointer to an object, for which I want to call a function

    - by user1795609
    So I've created an ADT which is a singly linked list made up of nodes. These Nodes each have a pointer to an object in them called data. Class Structure { struct Node { Object *data; Node *next; }; }; Node *head; I am trying to call a function in the object, like this: head = new Node; head -> data = new Object(); head -> next = NULL; cout << head -> data.print(); I keep getting the following error at compile. error: request for member 'print' in 'head-Structure::Node::data', which is of non-class type 'Object'*

    Read the article

  • Comparing Each Character in Java String

    - by user2760357
    I am a beginner at java, and I am trying to create two strings and compare each character. If there is a matching character or characters, the code has to print out the length of each string, without the matching characters. For example, if one string is "super," and the other is "perfect," the program should interpret the strings as superfect, and print out 9 However, if there is no matching part, like pencil and eraser, the code should printout 12, which is the length of two strings combined. Right now, I am having a problem with comparing each character, since I tried to use if(input_word.compareToIgnoreCase(input_word2) != 0) but it only compared the string as a whole.. any suggestion? Thank you for your efforts

    Read the article

  • Python: Check if all dictionaries in list are empty

    - by Brant
    I have a list of dictionaries. I need to check if all the dictionaries in that list are empty. I am looking for a simple statement that will do it in one line. Is there a single line way to do the following (not including the print)? l = [{},{},{}] # this list is generated elsewhere... all_empty = True for i in l: if i: all_empty = False print all_empty Somewhat new to python... I don't know if there is a shorthand built-in way to check this. Thanks in advance.

    Read the article

  • Parse and Break: why break cannot be used for getting out of "any" or "some" rule ?

    - by Rebol Tutorial
    Let say I have to parse a hierarchical set of tags <tag> <subtag1 attr1=value1 attr2=value2> <subtag1 attr1=value1 attr2=value2> <subtag1 attr1=value1 attr2=value2> </tag> Why can't I use break inside some or any to get out of a level hierarchy ? This would allow to do that kind of parsing instead of having a headache to do so ? I'm asking this because I read here http://www.codeconscious.com/rebol/parse-tutorial.html it would create an infinite loop This case produces an infinite loop. Because the BREAK is within a sub-rule of the rule that SOME is processing. The BREAK does not affect success/failure status or the input pointer - it just exits a rule early: rule-to-break: [(print "Break") break] == [(print "Break") break] parse "X" [some [rule-to-break] "X"] Break *Break* ... Break *Break*(escape)

    Read the article

  • Creating a PHP web page that enables you to reboot the server in Linux?

    - by Stuart
    I want to create a web page that allows the user to initiate a reboot on the linux server. Obviously this would only be avaliable for system admins and would also be controlled by using iptables. Below is a sample of code that I was thinking of using but I wanted to know if there is another way to do this and how also to use this in a web page? Also is there any thing else that I should consider? $command = "cat $pass | su -c 'shutdown -r now'"; $output = array(); try{ echo shell_exec($command); exec($command, $output); system($command, $output); } catch(Exception $e) { print "Unable to shutdown system...\n"; } foreach ($output as $line) { print "$line<br>"; } Thanks in advance.

    Read the article

  • Breaking up large DataGridView for printing

    - by Hal
    Hey, I've got a single-row, 40 column-long DataGridView that i need to print. Since i can neither print it directly (because A4 sheets won't cut it ;)) nor adjust its width to the width of the page itself (because the headers look terrible), i wanted to break the DataGridView to 4 separate pieces and display 10 columns per row (imagine: column 1 to 10 in the first line, column 11 to 21 four or five lines below, etc...). Is there an easy way to do this? I was leaning towards a more manual approach (using fors), but i'd love to know if there's a more elegant way. Cheers

    Read the article

  • Passing a multi-line string as an argument to a script in Windows

    - by Zack Mulgrew
    I have a simple python script like so: import sys lines = sys.argv[1] for line in lines.splitlines(): print line I want to call it from the command line (or a .bat file) but the first argument may (and probably will) be a string with multiple lines in it. How does one do this? Of course, this works: import sys lines = """This is a string It has multiple lines there are three total""" for line in lines.splitlines(): print line But I need to be able to process an argument line-by-line. EDIT: This is probably more of a Windows command-line problem than a Python problem. EDIT 2: Thanks for all of the good suggestions. It doesn't look like it's possible. I can't use another shell because I'm actually trying to invoke the script from another program which seems to use the Windows command-line behind the scenes.

    Read the article

  • In Python, is it better to use list comprehensions or for-each loops?

    - by froadie
    Which of the following is better to use and why? Method 1: for k, v in os.environ.items() print "%s=%s" % (k, v) Method 2: print "\n".join(["%s=%s" % (k, v) for k,v in os.environ.items()]) I tend to lead towards the first as more understandable, but that might just be because I'm new to Python and list comprehensions are still somewhat foreign to me. Is the second way considered more Pythonic? I'm assuming there's no performance difference, but I may be wrong. What would be the advantages and disadvantages of these 2 techniques? (Code taken from Dive into Python)

    Read the article

  • My cookies won't stay (PHP).

    - by RemiX
    I'm building an autologin system using cookies, but one fundamental part of the functionality of the cookies fails: they are non-persistent over different sessions - or even pages! In my login script, I set the cookies like this: setcookie('userID', $userID, time()+86400); // (edited after replies) $userID has a value. Then I print the $_COOKIE variable and it says array(['base_usid'] = 1); So that's good, but when I click the home page and print the $_COOKIE variable there, it says NULL. Does anyone see the problem?

    Read the article

  • Copy one column over another in a delimited file

    - by user275455
    For instance, I needed to remove column 25 and replace it with a copy of column 22 in a simple csv file with no embedded delimiters. The best I could come up with was the awkward looking: awk -F, '{ for(x=1;x<25;x++){printf("%s,", $x)};printf("%s,",$22);for(x=26;x<59;x++){printf ("%s,", $x)};print $59}' I would expect something like cut -d, -f1-24,23,26-59 to work but cut doesn't seem to want to print the same column two times... Is there a more elegant way to do it using anything typicaly available in a linux shell environment?

    Read the article

  • Why is this Python class copying another class contents?

    - by fjfnaranjo
    Hello guys. I'm trying to understand an estrange behavior in Python. I have the next python code: class IntContainer: listOfInts = [] def __init__(self, initListOfInts): for i in initListOfInts: self.listOfInts.append(i) def printInts(self): print self.listOfInts if __name__ == "__main__": intsGroup1 = [1,2,3,4] intsGroup2 = [4,5,6,7] intsGroups = [intsGroup1,intsGroup2] intsContainers = [] for ig in intsGroups: newIntContainer = IntContainer(ig) intsContainers.append(newIntContainer) for ic in intsContainers: print ic.listOfInts I expect to get something like: [1, 2, 3, 4] [4, 5, 6, 7] But i get: [1, 2, 3, 4, 4, 5, 6, 7] [1, 2, 3, 4, 4, 5, 6, 7] I have check the next question: http://stackoverflow.com/questions/1876905/why-is-python-reusing-a-class-instance-inside-in-function And a lot of Python reference, but I can not understand what is happening. I think is related with the newIntContainer identifier reutilization, but I do not understand it deeply. Why Python appears to reused the last reference for the new object, even if I have added it to a permanent list? What can I do to resolve this behavior? Thanks ;)

    Read the article

  • Why doesn't list.get(0).equals(null) work?

    - by Jessy
    The first index is set to null (empty), but it doesn't print the right output, why? //set the first index as null and the rest as "High" String a []= {null,"High","High","High","High","High"}; //add array to arraylist ArrayList<Object> choice = new ArrayList<Object>(Arrays.asList(a)); for(int i=0; i<choice.size(); i++){ if(i==0){ if(choice.get(0).equals(null)) System.out.println("I am empty"); //it doesn't print this output } }

    Read the article

  • Svn: how to remove all deleted files from repository ?

    - by Patrick
    I have a script in which I add all new files before to commit my working copy to my repository with this line: svn status | grep ^\? | awk '{print $2}' | xargs svn add I now want to add a line that delete from repository all deleted files in my working copy. In other terms, I cannot specify them one by one, and I need to detect them with svn status and then automatically remove them. However the line doesn't work. svn status | grep ^\! | awk '{print $2}' | xargs svn --force delete As you can see I've replaced "?" with "!" and "add" with "--force delete" Could you tell me why it doesn't work ? ps. I know it is a risky procedure. I've already discussed all about it. thanks thanks

    Read the article

  • Mechanize Submit Form Error: Insufficient items with name '10427'

    - by maneh
    I'm trying to submit a form with Mechanize, I have tried different ways, but the problem persists. Can anyone help me on this. Thank you in advance! This is the form I want to submit: http://www.stpairways.st/ This is the code that I'm using: def stp_airways(url): import re import mechanize br = mechanize.Browser() br.open(url) print br.title() br.select_form(name = "frmbook") br.form['TypeTrajet'] = ["1"] br.form['id_depart'] = ["11967"] br.form['id_arrivee'] = ["10427"] br.form['txtDateAller'] = "5/7/2014" br.form['txtDateRetour'] = "12/7/2014" br.form['TypePassager1u1000r0b1'] = ["1"] br.form['TypePassager2u1000r0b1'] = ["0"] br.form['TypePassager3u1000r0b1'] = ["0"] br.form['CodeIsoDeviseClient'] = ["17,20,23,24,25,26,27,28,29,30,31,33,34,36,37,64,65,67,68,70,73,80,81,95,96,103,147,151,152,159,160,162,169,170TP1TPF"] br.form['CodeIsoDeviseClient'] = ["EUR"] # submit response1 = br.submit() print response1.read()

    Read the article

  • remove the spaces...

    - by tekknolagi
    !/usr/bin/python import random lower_a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] upper_a = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] all = [] all = " ".join("".join(lower_a) + "".join(upper_a) + "".join(num)) all = all.split() x = 0 while x < 10: for i in range(7): a = random.choice(all) print a, print x += 1 what i want to do is remove the spaces from the output what it gives now is Z 3 a A I K R G B i N 9 c E v g E r A N 8 e B 6 d v H O c a V 8 c x y b g 2 W a T T f 8 H T r 6 E p D K l 5 p u x q 8 P Z 9 T n I W X n B Q

    Read the article

  • Python Regular Expression TypeError

    - by spaghettiwestern
    I am writing my first python program and I am running into a problem with regex. I am using regular expression to search for a specific value in a registry key. import _winreg import re key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{26A24AE4-039D-4CA4-87B4-2F83216020FF}") results=[] v = re.compile(r"(?i)Java") try: i = 0 while 1: name, value, type = _winreg.EnumValue(key, i) if v.search(value): results.append((name,value,type)) i += 1 except WindowsError: print for x in results: print "%-50s%-80s%-20s" % x I am getting the following error: exceptions.TypeError: expected string or buffer I can use the "name" variable and my regex works fine. For example if I make the following changes regex doesn't complain: v = re.compile(r"(?i)DisplayName") if v.search(name): Thanks for any help.

    Read the article

< Previous Page | 129 130 131 132 133 134 135 136 137 138 139 140  | Next Page >