Search Results

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

Page 69/358 | < Previous Page | 65 66 67 68 69 70 71 72 73 74 75 76  | Next Page >

  • PHP object help -> unexpected T_OBJECT_OPERATOR

    - by php-b-grader
    Please help me understand: print gettype(new CustomerObject()) prints: "object" (so it is an object) BUT print gettype((new CustomerObject())->get_customer()); prints: unexpected T_OBJECT_OPERATOR If I do it over two lines it works fine $object = new Customer($order->customer_id); print gettype($object); prints: object $customer = $object->get_customer(); print gettype($customer); prints: array It appears that the lines cannot be joined into a single call. Is this correct? and what is the logic behind that?

    Read the article

  • I can I separate multiple logical pages in a text file I create in Perl?

    - by Micah
    So far, I've been successful with generating output to individual files by opening a file for output as part of outer loop and closing it after all output is written. I had used a counting variable ($x) and appended .txt onto it to create a filename, and had written it to the same directory as my perl script. I want to step the code up a bit, prompt for a file name from the user, open that file once and only once, and write my output one "printed letter" per page. Is this possible in plain text? From what I understand, chr(12) is an ascii line feed character and will get me close to what I want, but is there a better way? Thanks in advance, guys. :) sub PersonalizeLetters{ print "\n\n Beginning finalization of letters..."; print "\n\n I need a filename to save these letters to."; print "\n Filename > "; $OutFileName = <stdin>; chomp ($OutFileName); open(OutFile, ">$OutFileName"); for ($x=0; $x<$NumRecords; $x++){ $xIndex = (6 * $x); $clTitle = @ClientAoA[$xIndex]; $clName = @ClientAoA[$xIndex+1]; #I use this 6x multiplier because my records have 6 elements. #For this routine I'm only interested in name and title. #Reset OutLetter array #Midletter has other merged fields that aren't specific to who's receiving the letter. @OutLetter = @MiddleLetter; for ($y=0; $y<=$ifLength; $y++){ #Step through line by line and insert the name. $WorkLine = @OutLetter[$y]; $WorkLine =~ s/\[ClientTitle\]/$clTitle/; $WorkLine =~ s/\[ClientName\]/$clName/; @OutLetter[$y] = $WorkLine; } print OutFile "@OutLetter"; #Will chr(12) work here, or is there something better? print OutFile chr(12); $StatusX = $x+1; print "Writing output $StatusX of $NumRecords... \n\n"; } close(OutFile); }

    Read the article

  • Concatenate, sort and swap array in Java

    - by sblck
    I am trying to concatenate two arrays into new array, sort in order, and swap two values of index. I'm kind of new to java and only use C before so having a hard time handling an Object. In main method it declares two object arrays IntVector vector = new IntVector(3); and IntVector vector2 = new IntVector(3); I can only do this if the types are int[], but I want to use as an object How should I code the concat, sort, and swap method? public class IntVector { private int[] items_; private int itemCount_; private IntVector(int[] data, int n) { items_ = data.clone(); itemCount_ = n; } public IntVector(int itemSize) { itemCount_ =0; if(itemSize<1) itemSize =10; items_ = new int[itemSize]; } public void push(int value) { if(itemCount_ + 1 >= items_.length) overflow(); items_[itemCount_++] = value; } public void log() { for (int i=0 ; i<itemCount_; ++i) { System.out.print(items_[i]); if(i<itemCount_ -1) System.out.println(); } } public void overflow() { int[] newItems = new int[items_.length * 2]; for(int i=0 ; i<itemCount_; ++i) { newItems[i] = items_[i]; } items_=newItems; } public int getValue(int index) { if(index < 0 || index >= itemCount_) { System.out.println("[error][IntVector][setValue] Incorrect index=" + index); return 0; } return items_[index]; } public void setValue(int index, int value) { if(index < 0 || index >= itemCount_) { System.out.println("[error][IntVector][setValue] Incorrect index=" + index); return ; } items_[index] = value; } public IntVector clone() { return new IntVector(items_, itemCount_); } public IntVector concat() { return null; } public IntVector sort() { return null; } public IntVector swap() { return null; } public static void main(String[] args) { IntVector vector = new IntVector(3); IntVector vector2 = new IntVector(3); vector.push(8); vector.push(200); vector.push(3); vector.push(41); IntVector cloneVector = vector.clone(); vector2.push(110); vector2.push(12); vector2.push(7); vector2.push(141); vector2.push(-32); IntVector concatResult = vector.concat(vector2); IntVector sortResult = concatResult.sort(); IntVector swapResult = sortResult.clone(); //swapResult.swap(1,5); System.out.print("vector : "); vector.log(); System.out.print("\n\ncloneVector : "); cloneVector.log(); System.out.print("\n\nvector2 : "); vector2.log(); System.out.print("\n\nconcatvector : "); concatResult.log(); System.out.print("vector : "); vector.log(); System.out.print("vector : "); vector.log(); } }

    Read the article

  • Sleeping a thread blocking stdin

    - by Sid
    Hey, I'm running a function which evaluates commands passed in using stdin and another function which runs a bunch of jobs. I need to make the latter function sleep at regular intervals but that seems to be blocking the stdin. Any advice on how to resolve this would be appreciated. The source code for the functions is def runJobs(comps, jobQueue, numRunning, limit, lock): while len(jobQueue) >= 0: print(len(jobQueue)); if len(jobQueue) > 0: comp, tasks = find_computer(comps, 0); #do something time.sleep(5); def manageStdin(): print "Global Stdin Begins Now" for line in fileinput.input(): try: print(eval(line)); except Exception, e: print e; --Thanks

    Read the article

  • Error compiling basic java code

    - by Michael Younani
    New to java. Practicing coding by following a book. Heres my code: class Motorcycle { //Three instance variables - make and color are strings. while a boolean refers to TRUE OR FLASE(in this case off or on) String make; String color; boolean engineState; void startEngine() { if (engineState == true) System.out.print("The engine is already on."); else { engineState = true; System.out.print("The engine is now on."); } void showAtts() { System.out.print("This motorcycle is a " + color + " " + make); if (engineState ==true) System.out.print("The engine is on."); else System.out.print("The engine is off."); } } } When I compile I get 2 errors: 1) illegal start of expression 2) ; expected I can't pin point the problem. If anyone can direct me or hint me please do.

    Read the article

  • Login with Google OAuth api and return url with variable

    - by user2833721
    I am using the Google API for login in my site and I appending my variable with URL and I want that variable in the return URL of OAuth API because of update purpose can I return back that variable For example: <a href="<?php echo($authUrl); ?>&kicker"> I append the kicker in $authUrl and when I return back from Oauth api print $me['displayName']; print $user['email']; print $me['gender']; print $me['id']; with this output I also want my variable "kicker" how can I get it

    Read the article

  • Find all occurrences of a substring in Python

    - by cru3l
    Python has string.find() and string.rfind() to get the index of a substring in string. I wonder, maybe there is something like string.find_all() which can return all founded indexes (not only first from beginning or first from end)? For example: string = "test test test test" print string.find('test') # 0 print string.rfind('test') # 15 #that's the goal print string.find_all('test') # [0,5,10,15]

    Read the article

  • Python lxml - returns null list

    - by Chris Finlayson
    I cannot figure out what is wrong with the XPATH when trying to extract a value from a webpage table. The method seems correct as I can extract the page title and other attributes, but I cannot extract the third value, it always returns an empty list? from lxml import html import requests test_url = 'SC312226' page = ('https://www.opencompany.co.uk/company/'+test_url) print 'Now searching URL: '+page data = requests.get(page) tree = html.fromstring(data.text) print tree.xpath('//title/text()') # Get page title print tree.xpath('//a/@href') # Get href attribute of all links print tree.xpath('//*[@id="financial"]/table/tbody/tr/td[1]/table/tbody/tr[2]/td[1]/div[2]/text()') Unless i'm missing something, it would appear the XPATH is correct: Chrome screenshot I checked Chrome console, appears ok! So i'm at a loss $x ('//*[@id="financial"]/table/tbody/tr/td[1]/table/tbody/tr[2]/td[1]/div[2]/text()') [ "£432,272" ]

    Read the article

  • How to test that variable is not equal to multiple things? Python

    - by M830078h
    This is the piece of code I have: choice = "" while choice != "1" and choice != "2" and choice != "3": choice = raw_input("pick 1, 2 or 3") if choice == "1": print "1 it is!" elif choice == "2": print "2 it is!" elif choice == "3": print "3 it is!" else: print "You should choose 1, 2 or 3" While it works, I feel that it's really clumsy, specifically the while clause. What if I have more acceptable choices? Is there a better way to make the clause?

    Read the article

  • Why is the data I am printing not in a table format

    - by udaya
    Hi This is my program .when i submit the print button i can print the datas but they are not aligned in the table formatthe format in which i need the print to be...How can i print in the correct format <html> <head> <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script> <script type="text/javascript"> function PrintElem(elem) { //alert('ddd'); Popup($(elem).text()); } function Popup(data) { var mywindow = window.open('', 'mydiv', 'height=400,width=600'); mywindow.document.write('<html><head><title>my div</title>'); /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />'); mywindow.document.write('</head><body >'); mywindow.document.write(data); mywindow.document.write('</body></html>'); mywindow.document.close(); mywindow.print(); return true; } </script> </head> <body> <div id="mydiv"> <table width="200" border="1"> <tr> <td>sss</td> <td>sssss;</td> <td>snssbsp;</td> </tr> <tr> <td>ssss;</td> <td>sssnbsp;</td> <td>snbsp;</td> </tr> <tr> <td>snbsp;</td> <td>snbsp;</td> <td>snbsp;</td> </tr> </table> </div> <input type="button" value="Print Div" onClick="PrintElem('#mydiv')" /> </body> </html>

    Read the article

  • How do I get the key of an item when doing a FOR loop through a dictionary or list in Python?

    - by Mike Hayes
    Hi I am new to Python. Say I have a list: list = ['A','B','C','D'] The key for each item respectively here is 0,1,2,3 - right? Now I am going to loop through it with a for loop... for item in list: print item That's great, I can print out my list. How do I get the key here? For example being able to do: print key print item on each loop? If this isn't possible with a list, where keys are not declared myself, is it possible with a Dictionary? Thanks

    Read the article

  • Python Continue Loop

    - by Rob B.
    I am using the following code from this tutorial (http://jeriwieringa.com/blog/2012/11/04/beautiful-soup-tutorial-part-1/). from bs4 import BeautifulSoup soup = BeautifulSoup (open("43rd-congress.html")) final_link = soup.p.a final_link.decompose() trs = soup.find_all('tr') for tr in trs: for link in tr.find_all('a'): fulllink = link.get ('href') print fulllink #print in terminal to verify results tds = tr.find_all("td") try: #we are using "try" because the table is not well formatted. This allows the program to continue after encountering an error. names = str(tds[0].get_text()) # This structure isolate the item by its column in the table and converts it into a string. years = str(tds[1].get_text()) positions = str(tds[2].get_text()) parties = str(tds[3].get_text()) states = str(tds[4].get_text()) congress = tds[5].get_text() except: print "bad tr string" continue #This tells the computer to move on to the next item after it encounters an error print names, years, positions, parties, states, congress However, I get an error saying that 'continue' is not properly in the loop on line 27. I am using notepad++ and windows powershell. How do I make this code work?

    Read the article

  • Format a timestamp into text

    - by user1257114
    I want to get the Modify date of a file and then format it into a human readable date. I am running a C program that gets information on when a particular file was last modified. My C Code contains a sytem cmd which contains a number of egreps, awks, seds separated by pipes. Using sed or awk or something similar, how can I convert 06 to June (This can be any month so an array or something is required) What I am trying to achieve is to end up with a string similar to: My C code contains: char string1[100] = ""; #define MAXCHAR 100 FILE *fp; char str[MAXCHAR], str2[MAXCHAR]; char* filename = "newfile"; /* stat: run 'stat' on the dtlName file to display status information. egrep: search for the pattern 'Modify' and print the lines containing it. awk: Get columns 2 & 3 sed: replace the . with a space, leaving 3 columns of output awk: only print cols 1 & 2 to newfile sed: replace '-' with ' ' in newfile awk: format output in newfile */ sprintf(string1, "/bin/stat %s \ | egrep Modify \ | /bin/awk '{print $2, $3}' \ | /bin/sed 's/\\./ /g' \ | /bin/awk '{print $1, $2}' \ | /bin/sed 's/-/ /g' \ | /bin/awk '{print $3,$2\", \"$1,\"at\",$4}' > newfile" , dtlName); system(string1); fp = fopen(filename, "r"); while (fgets(str, MAXCHAR, fp) != NULL) sprintf(str2,"%s", str); /* Write information to file */ DisplayReportFile (report); ReportEntry (report,L"Source file: %s, Created: %s\n\n",dtlName,str2);

    Read the article

  • Python server open all ports

    - by user1670178
    I am trying to open all ports using this code, why can I not create a loop to perform this function? http://www.kellbot.com/2010/02/tutorial-writing-a-tcp-server-in-python/ #!/usr/bin/python # This is server.py file ##server.py from socket import * #import the socket library n=1025 while n<1050: ##let's set up some constants HOST = '' #we are the host PORT = n #arbitrary port not currently in use ADDR = (HOST,PORT) #we need a tuple for the address BUFSIZE = 4096 #reasonably sized buffer for data ## now we create a new socket object (serv) ## see the python docs for more information on the socket types/flags serv = socket( AF_INET,SOCK_STREAM) ##bind our socket to the address serv.bind((ADDR)) #the double parens are to create a tuple with one element serv.listen(5) #5 is the maximum number of queued connections we'll allow serv = socket( AF_INET,SOCK_STREAM) ##bind our socket to the address serv.bind((ADDR)) #the double parens are to create a tuple with one element serv.listen(5) #5 is the maximum number of queued connections we'll allow print 'listening...' n=n+1 conn,addr = serv.accept() #accept the connection print '...connected!' conn.send('TEST') conn.close() How do I make this work so that I can specify input range and have the server open all ports up to 65535? #!/usr/bin/python # This is server.py file from socket import * #import the socket library startingPort=input("\nPlease enter starting port: ") startingPort=int(startingPort) #print startingPort def connection(): ## let's set up some constants HOST = '' #we are the host PORT = startingPort #arbitrary port not currently in use ADDR = (HOST,PORT) #we need a tuple for the address BUFSIZE = 4096 #reasonably sized buffer for data def socketObject(): ## now we create a new socket object (serv) serv = socket( AF_INET,SOCK_STREAM) def bind(): ## bind our socket to the address serv = socket( AF_INET,SOCK_STREAM) serv.bind((ADDR)) #the double parens are to create a tuple with one element serv.listen(5) #5 is the maximum number of queued connections we'll allow serv = socket( AF_INET,SOCK_STREAM) print 'listening...' def accept(): conn,addr = serv.accept() #accept the connection print '...connected!' conn.send('TEST') def close(): conn.close() ## Main while startingPort<65535: connection() socketObject() bind() accept() startingPort=startingPort+1

    Read the article

  • Problems with sys.stdout.write() with time.sleep() in a function

    - by philipjkim
    What I wanted is printing out 5 dots that a dot printed per a second using time.sleep(), but the result was 5 dots were printed at once after 5 seconds delay. Tried both print and sys.stdout.write, same result. Thanks for any advices. import time import sys def wait_for(n): """Wait for {n} seconds. {n} should be an integer greater than 0.""" if not isinstance(n, int): print 'n in wait_for(n) should be an integer.' return elif n < 1: print 'n in wait_for(n) should be greater than 0.' return for i in range(0, n): sys.stdout.write('.') time.sleep(1) sys.stdout.write('\n') def main(): wait_for(5) # FIXME: doesn't work as expected if __name__ == '__main__': try: main() except KeyboardInterrupt: print '\nAborted.'

    Read the article

  • Manipulating values from database table with php

    - by charliecodex23
    I currently have 5 tables in MySQL database. Some of them share foreign keys and are interdependent of each other. I am displaying classes accordingly to their majors. Each class is taught during the fall, spring or all_year. In my database I have a table named semester which has an id, year, and semester fields. The semester field in particular is a tinyint that has three values 0, 1, 2. This signifies the fall, spring or all_year. When I display the query instead of having it show 0 or 1 or 2 can I have it show fall, spring etc? Extra: How can I add space to the end of each loop so the data doesn't look clustered? Key 0 Fall 1 Spring 2 All-year PHP <? try { $pdo = new PDO ("mysql:host=$hostname;dbname=$dbname","$username","$pw"); } catch (PDOException $e) { echo "Failed to get DB handle: " . $e->getMessage() . "\n"; exit; } $query = $pdo->prepare("SELECT course.name, course.code, course.description, course.hours, semester.semester, semester.year FROM course LEFT JOIN major_course_xref ON course.id = major_course_xref.course_id LEFT JOIN major ON major.id = major_course_xref.major_id LEFT JOIN course_semester_xref ON course.id = course_semester_xref.course_id LEFT JOIN semester ON course_semester_xref.semester_id = semester.id"); $query->execute(); if ($query->execute()){ while ($row = $query->fetch(PDO::FETCH_ASSOC)){ print $row['name'] . "<br>"; print $row['code'] . "<br>"; print $row['description'] . "<br>"; print $row['hours'] . " hrs.<br>"; print $row['semester'] . "<br>"; print $row['year'] . "<br>"; } } else echo 'Could not fetch results.'; unset($pdo); unset($query); ?> Current Display Computer Programming I CPSC1400 Introduction to disciplined, object-oriented program development. 4 hrs. 0 2013 Desire Display Computer Programming I CPSC1400 Introduction to disciplined, object-oriented program development. 4 hrs. Fall 2013

    Read the article

  • How is it possible my array is broken?

    - by user1812765
    I have this piece of code: public lot merge (lot otherlot){ wafer[] mWaferarray = new wafer[16]; byte[] bytearray = new byte[16]; wafer resultwafer = new wafer(bytearray); wafer w1; wafer w2; int i; int[][] assignmentmatrix = HungarianAlgorithm.computeAssignments(convertinttofloat (solutionmatrix(otherlot))); for (i=0; i != assignmentmatrix.length ;i++){ w1 = otherlot.getWaferarray()[assignmentmatrix[i][0]]; w2 = getWaferarray()[assignmentmatrix[i][1]]; resultwafer.setWafer(w1.wafercompare(w2)); mWaferarray[i] = resultwafer; mWaferarray[i].print(); } System.out.println("HERE\n"); mWaferarray[5].toString(); resultlot = new lot(mWaferarray); resultlot.print();// Problem occurs here. return resultlot; } As you can see I create an array of wafers (selfdefined class). Then I fill this up with new wafers. When I print this array (mWaferarray[i].print()) it gives me the wanted results. But when I go out of the "for"-loop the array is broken and it is as if the last item I add to mWaferarray fills it up (the entire array, 16 long, is filled with this wafer). So if run this program this is what I get: 1011110010111100 0011011111111110 0111110111101101 1010111001101111 0110110111101111 1010110101111010 1010110111011110 1011111010111100 1111110011101110 0111111111011011 1111111111011010 1101111011111010 1010110101011110 0101111011011010 1011111011011000 0101111011011010 HERE 0101111011011010 0101111011011010 0101111011011010 0101111011011010 0101111011011010 0101111011011010 0101111011011010 0101111011011010 0101111011011010 0101111011011010 0101111011011010 0101111011011010 0101111011011010 0101111011011010 0101111011011010 0101111011011010 As you can see it is as if the array is filled with the last wafer. I have been looking at this for some time now, I hope you guy can help me out. Thx in advance PS: my print functions are written like this: void print(){ int j; for (j=0; j != waferarray.length ;j++){ waferarray[j].print(); } } EDIT: added code for lot this is the beginning of the lot class public class lot { wafer[] waferarray = new wafer[16]; lot resultlot; public lot (wafer wafer1,wafer wafer2,wafer wafer3,wafer wafer4, wafer wafer5,wafer wafer6,wafer wafer7,wafer wafer8, wafer wafer9,wafer wafer10,wafer wafer11,wafer wafer12, wafer wafer13,wafer wafer14,wafer wafer15,wafer wafer16){ waferarray[0] = wafer1; waferarray[1] = wafer2; waferarray[2] = wafer3; waferarray[3] = wafer4; waferarray[4] = wafer5; waferarray[5] = wafer6; waferarray[6] = wafer7; waferarray[7] = wafer8; waferarray[8] = wafer9; waferarray[9] = wafer10; waferarray[10] = wafer11; waferarray[11] = wafer12; waferarray[12] = wafer13; waferarray[13] = wafer14; waferarray[14] = wafer15; waferarray[15] = wafer16; } public lot (wafer[] thiswaferarray){ waferarray = thiswaferarray; }

    Read the article

  • problem in extracting the data from text file

    - by parijat24
    hello , i am new to python , and I want to extract the data from this format FBpp0143497 5 151 5 157 PF00339.22 Arrestin_N Domain 1 135 149 83.4 1.1e-23 1 CL0135 FBpp0143497 183 323 183 324 PF02752.15 Arrestin_C Domain 1 137 138 58.5 6e-16 1 CL0135 FBpp0131987 60 280 51 280 PF00089.19 Trypsin Domain 14 219 219 127.7 3.7e-37 1 CL0124 to this format FBpp0143497 5 151 Arrestin_N 1.1e-23 FBpp0143497 183 323 Arrestin_C 6e-16 I have written code in hope that it works but it does not work , please help! file = open('/ddfs/user/data/k/ktrip_01/hmm.txt','r') rec = file.read() for line in rec : field = line.split("\t") print field print field[:] print '>',field[0] print field[1], field[2], field[6], field[12] the hmmtext file is FBpp0143497 5 151 5 157 PF00339.22 Arrestin_N Domain 1 135 149 83.4 1.1e-23 1 CL0135 FBpp0143497 183 323 183 324 PF02752.15 Arrestin_C Domain 1 137 138 58.5 6e-16 1 CL0135 FBpp0131987 60 280 51 280 PF00089.19 Trypsin Domain 14 219 219 127.7 3.7e-37 1 CL0124

    Read the article

  • Python: Problems finding string in website source code

    - by j00niner
    I open a website with urlopen. I then put the website sourcecode into a variable like so source = website.read() When I just print the source it comes out formatted correctly, however when I try to iterate through each line each character is it's own line. for example when I just print it looks like this <HTML> title</html> When I do this for line in source: print line it looks like this < H T M L ... etc I need to find a string that starts with "var" and then print that entire line.

    Read the article

< Previous Page | 65 66 67 68 69 70 71 72 73 74 75 76  | Next Page >