Search Results

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

Page 48/782 | < Previous Page | 44 45 46 47 48 49 50 51 52 53 54 55  | Next Page >

  • Python: re-initialize a function's default value for subsequent calls to the function.

    - by Peter Stewart
    I have a function that calls itself to increment and decrement a stack. I need to call it a number of times, and I'd like it to work the same way in subsequent calls but, as expected, it doesn't re-use the default value. I've read that this is a newbie trap and I've seen suggested solutions, but I haven't been able to make any solution work. It would be nice to be able to "fun.reset" def a(x, stack = [None]): print x,' ', stack if x > 5: temp = stack.pop() if x <=5: stack.append(1) if stack == []: return a(x + 1) print a(0) print a(2) #second call print a(3) #third call I expected this to work, but it doesn't. print a(0, [None]) print a(2, [None]) #second call print a(3, [None]) #third call Can I reset the function to it's initial state? Any help would be appreciated.

    Read the article

  • Making change recursively: How do I modify my algorithm to print all combinations?

    - by cb
    I have an algorithm that recursively makes change in the following manner: public static int makeChange(int amount, int currentCoin) { //if amount = zero, we are at the bottom of a successful recursion if (amount == 0){ //return 1 to add this successful solution return 1; //check to see if we went too far }else if(amount < 0){ //don't count this try if we went too far return 0; //if we have exhausted our list of coin values }else if(currentCoin < 0){ return 0; }else{ int firstWay = makeChange(amount, currentCoin-1); int secondWay = makeChange(amount - availableCoins[currentCoin], currentCoin); return firstWay + secondWay; } } However, I'd like to add the capability to store or print each combination as they successfully return. I'm having a bit of a hard time wrapping my head around how to do this. The original algorithm was pretty easy, but now I am frustrated. Any suggestions? CB

    Read the article

  • How do you print a limited number of characters?

    - by Mike Pateras
    Sorry to put a post up about something so simple, but I don't see what I'm doing wrong here. char data[1024]; DWORD numRead; ReadFile(handle, data, 1024, &numRead, NULL); if (numRead > 0) printf(data, "%.5s"); My intention with the above is to read data from a file, and then only print out 5 characters. However, it prints out all 1024 characters, which is contrary to what I'm reading here. The goal, of course, is to do something like: printf(data, "%.*s", numRead); What am I doing wrong here?

    Read the article

  • python - sys.argv and flag identification

    - by tekknolagi
    when I accept arguments how do I check if two show up at the same time without having a compound conditional i.e. #!/usr/bin/python import random, string import mymodule import sys z = ' '.join(sys.argv[2:]) q = ''.join(sys.argv[3:]) a = ''.join(sys.argv[2:]) s = ' '.join(sys.argv[1:]) flags = sys.argv[1:5] commands = [["-r", "reverse string passed next with no quotes needed."], ["-j", "joins arguments passed into string. no quotes needed."], ["--palindrome", "tests whether arguments passed are palindrome or not. collective."],["--rand","passes random string of 10 digits/letters"]] try: if "-r" in flags: if "-j" in flags: print mymodule.reverse(q) if not "-j" in flags: print mymodule.reverse(z) if "-j" in flags: if not "-r" in flags: print a if "--palindrome" in flags: mymodule.ispalindrome(z) if (not "-r" or not "-j" or not "--palindrome") in flags: mymodule.say(s) if "--rand" in flags: print(''.join([random.choice(string.ascii_letters+"123456789") for f in range(10)])) if not sys.argv[1]: print mymodule.no_arg_error if "--help" in flags: print commands except: print mymodule.no_arg_error i just want to be able to say if "-r" and "-j" in flags in no particular order: do whatever

    Read the article

  • Socket.recv works but not gets or read?

    - by Earlz
    Hello I've been messing around with Sockets in Ruby some and came across some example code that I tried modifying and broke. I want to know why it's broken. Server: require "socket" dts = TCPServer.new('127.0.0.1', 20000) loop do Thread.start(dts.accept) do |s| print(s, " is accepted\n") s.write(Time.now) print(s, " is gone\n") s.close end end Client that works: require 'socket' streamSock = TCPSocket.new( "127.0.0.1", 20000 ) streamSock.print( "Hello\n" ) str = streamSock.recv( 100 ) print str streamSock.close Client that is broken require 'socket' streamSock = TCPSocket.new( "127.0.0.1", 20000 ) streamSock.print( "Hello\n" ) str=streamSock.read #this line modified print str streamSock.close I know that the streamSock.print is unnecessary (as well as the naming scheme being non-ruby) but I don't understand why read doesn't work while recv does, Why is this?

    Read the article

  • Using __str__ representation for printing objects in containers in Python

    - by BobDobbs
    I've noticed that when an instance with an overloaded str method is passed to the print() function as an argument, it prints as intended. However, when passing a container that contains one of those instances to print(), it uses the repr method instead. That is to say, print(x) displays the correct string representation of x, and print(x, y) works correctly, but print([x]) or print((x, y)) prints the repr representation instead. First off, why does this happen? Secondly, is there a way to correct that behavior of print() in this circumstance?

    Read the article

  • how to use @ in python.. and the @property and the @classmethods

    - by zjm1126
    this is my code: def a(): print 'sss' @a() def b(): print 'aaa' b() and the Traceback is: sss Traceback (most recent call last): File "D:\zjm_code\a.py", line 8, in <module> @a() TypeError: 'NoneType' object is not callable so how to use the '@' thanks updated class a: @property def b(x): print 'sss' aa=a() print aa.b it print : sss None how to use @property thanks updated2 and the classmethods: class a: @classmethods def b(x): print 'sss' aa=a() print aa.b the Traceback is : Traceback (most recent call last): File "D:\zjm_code\a.py", line 5, in <module> class a: File "D:\zjm_code\a.py", line 6, in a @classmethods NameError: name 'classmethods' is not defined

    Read the article

  • How to print the Control identifiers of a window to a document in Pywinauto.

    - by Swetha
    Hi All, I am trying to automate installation of an application using Pywinauto.During the installation the last window shows some warning or error messages in few cases and later the system begins to restart.My objective is to capture the the Warning messages which is possible by app.top_window_()._ctrl_identifiers() np.Notepad.Edit.TypeKeys(a,with_spaces=True, with_tabs=True, with_newlines=True) This is returning a list which contains all the messages of the screen. Second line is where i am trying to print the list object in the notepad.But its throwing some exceptions Traceback (most recent call last): File "", line 1, in np.Notepad.Edit.TypeKeys(a,with_spaces=True, with_tabs=True, with_newlines=True) File "C:\Python26\pywinauto\controls\HwndWrapper.py", line 950, in TypeKeys turn_off_numlock) File "C:\Python26\pywinauto\SendKeysCtypes.py", line 629, in SendKeys keys = parse_keys(keys, with_spaces, with_tabs, with_newlines) File "C:\Python26\pywinauto\SendKeysCtypes.py", line 538, in parse_keys c = string[index] KeyError: 0 Could anyone let me know how to do this or if there is other way in which this can be handled with an example. Thanks a lot in advance. Swetha

    Read the article

  • Printing complex widgets in Qt

    - by Jens
    I have a complex widget with tons of different subwidgets, e.g. subclasses of QLabel. I want to print this widget, but obviously I do not want to print the background, I want to print with differing text colors or have the style of frames slightly modified. As I do not really want to iterate through all subwidgets with a special "print" function, which I would need to attach to all widgets (how to add "print" to a QLabel?), I would like to use paintEvent. If I have a hierarchy MyWidget - derived from - some QWidget, I would like to insert a sublayer MyWidget - MyPrintWidget - some QWidget, where myPrintWidget::paintEvent would check, if the current print is going to the screen (thus call QWidget::paintEvent), else if we are printing to the printer, call some function MyPrintWidget::drawWidget instead. Is this the right way to print-enable a widget? How can I figure out in paintEvent, that I'm printing to a printer instead of the screen? Is there a good example of printing complex widgets?

    Read the article

  • Print new line in the source-code with jQuery.

    - by Kucebe
    I have a simple function in jQuery that creates new elements in the DOM. the problem is in the html source code, it append every element in the same line, and it's very bad to read. function _loadNewElements(elements){ for(var i=0; i<elements.length; i++){ var fixedElement = $('<img />') var position = elements[i].position; var cssMap = { 'position': 'fixed', 'top': position.top + "px", 'left': position.left + "px" }; fixedElement.css(cssMap); fixedElement.addClass("fixedTag"); fixedElement.attr('alt', elements[i].text); fixedElement.attr('src', "elements/" + elements[i].id + ".png"); fixedElement.appendTo($('#board')); //i'd like to print something here like ("\n"); } } I tried document.write("\n") but in this context it doesn't work. Any solution?

    Read the article

  • How to print absolute line number in uncaught exception?

    - by DSblizzard
    When error occured Python prints something like this: Traceback (most recent call last): File "<stdin>", line 2, in <module> File "<stdin>", line 8, in m File "<stdin>", line 5, in exec_st File "<stdin>", line 9, in exec_assign File "<stdin>", line 48, in ref_by_id IndexError: list index out of range where 2, ... , 48 are relative line numbers which are not very convenient. How to print absolute line numbers in such error messages? EDIT: Maybe it's a dumb question, but answer will facilitate development a little. I'm printing text in several files. When done, press shortcut which runs python and copies contents of current file to console. Proposed solution forces to press excess keystrokes (Ctrl+S, Alt+Tab) and create additional files. I hope I have put it clear.

    Read the article

  • How to print a specific value in array in PHP?

    - by cateye
    array(2) { [0]=> object(stdClass)#144 (7) { ["id"]=> string(1) "2" ["name"]=> string(8) "name1" ["value"]=> string(22) "Lorem Ipsum Dolar Amet" ["type"]=> string(8) "textarea" ["group"]=> string(1) "1" ["published"]=> string(1) "1" ["ordering"]=> string(1) "1" } [1]=> object(stdClass)#145 (7) { ["id"]=> string(1) "4" ["name"]=> string(6) "Link1" ["value"]=> string(36) "abcabcab" ["type"]=> string(4) "link" ["group"]=> string(1) "1" ["published"]=> string(1) "1" ["ordering"]=> string(1) "2" } } I want to print only "value" (abcabcab) of id=4. How can I achieve this?

    Read the article

  • How to Print the contents of a textbox in C++/CLI?

    - by Smoka
    I'm still learning C++ coding. I'm having troubles getting say ResultsBox-Text to printer successfully. What is the proper way to print in C++/CLI? I think im missing something simple. Ive tried multiple different routes/syntax's that ive read online/ in books. All of which got me to a dead end. Please even a rundown on the method of printing in any C based language might point me the right way. Thank you.

    Read the article

  • Extracting methods body from a class of Java Source Code

    - by Muhammad Asaduzzaman
    Hi, I want to extract method body from a Java Source Code. Suppose I have the following code: public class A{ public void print(){ System.out.println("Print This thing"); System.out.println("Print This thing"); System.out.println("Print This thing"); } } My objective is not to extract the method name (in this case print) but also the bode of the method(In this case the three print statement inside the print method). Can anyone suggest how can I do so? Is their any library available for doing so.

    Read the article

  • Drop into read-eval-print loop from PHP code?

    - by Mickey
    Is there a way to drop into a read-eval-print loop from inside PHP code during execution, in a script that was run from the command line? That is, like php -a or phpsh? Or do I have to re-implement a REPL from scratch? I can't find any way to do it. To clarify: the reason why I need to do this is that I want to automatically include all the files in my project once the REPL starts, instead of having to manually include everything by hand.

    Read the article

  • How can I print a text in two columns using Java Swing?

    - by Jonas
    I have a longer text saved in a String. I would like to print the text in two columns on a single page. How can I do this using Java Swing? I don't understand how I can wrap the text when it's time to use a new line. I have read Lesson: Printing in the Java tutorial, but I haven't found any useful methods for working with text or Strings except FontMetrics. Is there any good methods in the Java API for this or is there any good library I can use for this?

    Read the article

  • Perl - Reading .txt files line-by-line and using compare function (printing non-matches only once)

    - by Kurt W
    I am really struggling and have spent about two full days on this banging my head against receiving the same result every time I run this perl script. I have a Perl script that connects to a vendor tool and stores data for ~26 different elements within @data. There is a foreach loop for @data that breaks the 26 elements into $e-{'element1'), $e-{'element2'), $e-{'element3'), $e-{'element4'), etc. etc. etc. I am also reading from the .txt files within a directory (line-by-line) and comparing the server names that exist within the text files with what exists in $e-{'element4'}. The Problem: Matches are working perfectly and only printing one line for each of the 26 elements when there is a match, however non-matches are producing one line for every entry within the .txt files (37 in all). So if there are 100 entries (each entry having 26 elements) stored within @data, then there are 100 x 37 entries being printed. So for every non-match in the: if ($e-{'element4'} eq '6' && $_ =~ /$e-{element7}/i) statement below, I am receiving a print out saying that there is not a match. 37 entries for the same identical 26 elements (because there are 37 total entries in all of the .txt files). The Goal: I need to print out only 1 line for each unique entry (a unique entry being $e-{element1} thru $e-{element26}). It is already printing one 1 line for matches, but it is printing out 37 entries when there is not a match. I need to treat matches and non-matches differently. Code: foreach my $e (@data) { # Open the .txt files stored within $basePath and use for comparison: opendir(DIRC, $basePath . "/") || die ("cannot open directory"); my @files=(readdir(DIRC)); my @MPG_assets = grep(/(.*?).txt/, @files); # Loop through each system name found and compare it with the data in SC for a match: foreach(@MPG_assets) { $filename = $_; open (MPGFILES, $basePath . "/" . $filename) || die "canot open the file"; while(<MPGFILES>) { if ($e->{'element4'} eq '6' && $_ =~ /$e->{'element7'}/i) { ## THIS SECTION WORKS PERFECTLY AND ONLY PRINTS MATCHES WHERE $_ ## (which contains the servernames (1 per line) in the .txt files) ## EQUALS $e->{'element7'}. print $e->{'element1'} . "\n"; print $e->{'element2'} . "\n"; print $e->{'element3'} . "\n"; print $e->{'element4'} . "\n"; print $e->{'element5'} . "\n"; # ... print $e->{'element26'} . "\n"; } else { ## **THIS SECTION DOES NOT WORK**. FOR EVERY NON-MATCH, THERE IS A ## LINE PRINTED WITH 26 IDENTICAL ELEMENTS BECAUSE ITS LOOPING THRU ## THE 37 LINES IN THE *.TXT FILES. print $e->{'element1'} . "\n"; print $e->{'element2'} . "\n"; print $e->{'element3'} . "\n"; print $e->{'element4'} . "\n"; print $e->{'element5'} . "\n"; # ... print $e->{'element26'} . "\n"; } # End of 'if ($e->{'element4'} eq..' statement } # End of while loop } # End of 'foreach(@MPG_assets)' } # End of 'foreach my $e (@data)' I think I need something to identical unique elements and define what fields make up a unique element but honestly I have tried everything I know. If you would be so kind to provide actual code fixes, that would be wonderful because I am headed to production with this script quite soon. Also. I am looking for code (ideally) that is very human-readable because I will need to document it so others can understand. Please let me know if you need additional information.

    Read the article

  • Html.ActionLink in a button

    - by Pomster
    I Am trying to connect to a method in my controller, with a button. I can connect though this link: @Html.ActionLink("Print", "Print", new { id = Model.SalesContractId}) But i Don't want a link, i want my button on my dialog to do it. I have tried the following: $('#btnDialogPrint').click(function () { location.href = '<%= Url.Action("Print", "Print", new { id = Model.SalesContractId}) %>'; }); But it just redirect me to a page that say bad request. namespace Contract.Controllers { public class ContractController : Controller { CompassEntities db = new CompassEntities(); public ActionResult Print(int id) { return View(""); // This can be removed and Print code may be added } Don't worry about the code inside i will get to that once i get inside this method. Could i maybe attach a link here? <input type="button" value="Print" id="btnDialogPrint" />

    Read the article

  • How do I print array values in a range when values are supplied?

    - by dcp3450
    My php reads in xml and I want to ouput the values within a given range. I have no way of knowing the size of the array or the range. However, I do know where to start; I have a $key that holds my current location. I also know where to stop; I have the word "ENDEVENTS" between each set. I want to get the values from my current position ($key) to my end position ("ENDEVENTS"). for example i may have an array set like this: Array( [0]=1 [1]=apple [2]=straw [3]=bike [4]=ENDEVENTS [5]=15 [6]=hair [7]=shirt [8]=nose [9]=kiwi [10]=ENDEVENTS ) My code knows when I'm on 15 (in this example $key=5). I want to print 6 through 9. I tried using foreach but it's thats causing issues with what I'm trying to produce. Any ideas?

    Read the article

  • Trying to use a list iterator to print out entire linked list in Java. Infinite loop for some reaso

    - by Matt
    I created my list: private static List list = new LinkedList(); and my iterator: ListIterator itr = list.listIterator(); and use this code to try to print out the list... Only problem is, it never comes out of the loop. When it reaches the tail, shouldn't it come out of the loop, because there is no next? Or is it going back to the head like a circular linked list? It is printing so quickly and my computer locks up shortly after, so I can't really tell what is going on. while (itr.hasNext()) System.out.println(itr.next());

    Read the article

  • Print column A only if any of B, C, D, E & G contains Failed using Linux shell

    - by user3626342
    A B C ............ till G sucnpde067.advancemags.com- Successful Full FS_UNIX_801_Fri_C Full_Backup 0B Failed Full FS_UNIX_801_Fri_B Full_Backup 0B ............ till G sucnpde066.advancemags.com- Successful Full FS_UNIX_801_Fri_C Full_Backup 0B Successful Full FS_UNIX_801_Fri_C Full_Backup 0B ............ till G slnssde052.advancemags.com- Failed Full FS_UNIX_801_Fri_B Full_Backup 0B Successful Full FS_UNIX_801_Fri_C Full_Backup 0B ........... till G slnssde048.advancemags.com- Failed Full FS_UNIX_801_Fri_B Full_Backup 0B Failed Full FS_UNIX_801_Fri_B Full_Backup 0B ............ till G Print column A only if any of B, C, D, E & G contains Failed using Linux shell Note -Coulmns are tab/comma seperated

    Read the article

  • how to print correctly the handling thread on Windows?

    - by make
    Hi, Could someone please tell us on how to print correctly the handling thread in windows? Actually I tried several ways but it doesn't return the right number as in Unix-variant, as such e.g.: cout << " with thread " << pthread_self << endl; cout << " with thread " << pthread_self().p << endl; Thanks for your replies:

    Read the article

< Previous Page | 44 45 46 47 48 49 50 51 52 53 54 55  | Next Page >