Search Results

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

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

  • How to handle similar items in rails MVC?

    - by mocker
    I'm working on building a pretty simple site mainly as an exercise in learning more about rails. You can see my rough progress at statific.com. It's working pretty much as I wanted it for keeping track of server information, but now I'd like to expand it to other things, next on the list being firewalls. I can pretty easily duplicate all the models, views, etc.. that I have for my servers. The problem I see with that is that it isn't very DRY since most of the code would look the same, the only difference would be the attributes I have setup for firewalls would be different than for servers. I know in plain ruby this is pretty simple, you can have a 'Product' w/ common attributes ('manufacturer', 'model') and then have children with more specific attributes. Does the same type of concept exist for rails, or am I just over thinking this?

    Read the article

  • Printing array with delimiters in Perl

    - by Mark B
    I have an array in Perl I want to print with space delimiters between each element, except every 10th element which should be newline delimited. There aren't any spaces in the elements if that matters. I've written a function to do it with for and a counter, but I wondered if there's a better/shorter/canonical Perl way, perhaps a special join syntax or similar. My function to illustrate: sub PrintArrayWithNewlines { my $counter = 0; my $newlineIndex = shift @_; foreach my $item (@_) { ++$counter; print "$item"; if($counter == $newlineIndex) { $counter = 0; print "\n"; } else { print " "; } } }

    Read the article

  • How to flush the input stream in python?

    - by jinxed_coder
    I'm writing a simple alarm utility in Python. #!/usr/bin/python import time import subprocess import sys alarm1 = int(raw_input("How many minutes (alarm1)? ")) while (1): time.sleep(60*alarm1) print "Alarm1" sys.stdout.flush(); doit = raw_input("Continue (Y/N)?[Y]: ") print "Input",doit if doit == 'N' or doit=='n': print "Exiting....." break I want to flush or discard all the key strokes that were entered while the script was sleeping and only accept the key strokes after the raw_input() is executed.

    Read the article

  • Performance of delegate and method group

    - by BlueFox
    Hi I was investigating the performance hit of creating Cachedependency objects, so I wrote a very simple test program as follows: using System; using System.Collections.Generic; using System.Diagnostics; using System.Web.Caching; namespace Test { internal class Program { private static readonly string[] keys = new[] {"Abc"}; private static readonly int MaxIteration = 10000000; private static void Main(string[] args) { Debug.Print("first set"); test7(); test6(); test5(); test4(); test3(); test2(); Debug.Print("second set"); test2(); test3(); test4(); test5(); test6(); test7(); } private static void test2() { DateTime start = DateTime.Now; var list = new List<CacheDependency>(); for (int i = 0; i < MaxIteration; i++) { list.Add(new CacheDependency(null, keys)); } Debug.Print("test2 Time: " + (DateTime.Now - start)); } private static void test3() { DateTime start = DateTime.Now; var list = new List<Func<CacheDependency>>(); for (int i = 0; i < MaxIteration; i++) { list.Add(() => new CacheDependency(null, keys)); } Debug.Print("test3 Time: " + (DateTime.Now - start)); } private static void test4() { var p = new Program(); DateTime start = DateTime.Now; var list = new List<Func<CacheDependency>>(); for (int i = 0; i < MaxIteration; i++) { list.Add(p.GetDep); } Debug.Print("test4 Time: " + (DateTime.Now - start)); } private static void test5() { var p = new Program(); DateTime start = DateTime.Now; var list = new List<Func<CacheDependency>>(); for (int i = 0; i < MaxIteration; i++) { list.Add(() => { return p.GetDep(); }); } Debug.Print("test5 Time: " + (DateTime.Now - start)); } private static void test6() { DateTime start = DateTime.Now; var list = new List<Func<CacheDependency>>(); for (int i = 0; i < MaxIteration; i++) { list.Add(GetDepSatic); } Debug.Print("test6 Time: " + (DateTime.Now - start)); } private static void test7() { DateTime start = DateTime.Now; var list = new List<Func<CacheDependency>>(); for (int i = 0; i < MaxIteration; i++) { list.Add(() => { return GetDepSatic(); }); } Debug.Print("test7 Time: " + (DateTime.Now - start)); } private CacheDependency GetDep() { return new CacheDependency(null, keys); } private static CacheDependency GetDepSatic() { return new CacheDependency(null, keys); } } } But I can't understand why these result looks like this: first set test7 Time: 00:00:00.4840277 test6 Time: 00:00:02.2041261 test5 Time: 00:00:00.1910109 test4 Time: 00:00:03.1401796 test3 Time: 00:00:00.1820105 test2 Time: 00:00:08.5394884 second set test2 Time: 00:00:07.7324423 test3 Time: 00:00:00.1830105 test4 Time: 00:00:02.3561347 test5 Time: 00:00:00.1750100 test6 Time: 00:00:03.2941884 test7 Time: 00:00:00.1850106 In particular: 1. Why is test4 and test6 much slower than their delegate version? I also noticed that Resharper specifically has a comment on the delegate version suggesting change test5 and test7 to "Covert to method group". Which is the same as test4 and test6 but they're actually slower? 2. I don't seem a consistent performance difference when calling test4 and test6, shouldn't static calls to be always faster?

    Read the article

  • awk output to a file

    - by Harish
    I need help in moving the contents printed by awk to a text file. THis is a continuation of previous quesion I have to move all the contents into the same file so it is appending. To be specific nawk -v file="$FILE" 'BEGIN{RS=";"} /select/{ gsub(/.*select/,"select");gsub(/\n+/,"");print file,$0;} /update/{ gsub(/.*update/,"update");gsub(/\n+/,"");print file,$0;} /insert/{ gsub(/.*insert/,"insert");gsub(/\n+/,"");print file,$0;} ' "$FILE" How to get the print results to a text file appended one after the other in the same file?

    Read the article

  • READING stderr from within Awk

    - by Dave
    I want to keep SSH debug info separate (and logged) from other input. However, if I simply redirect stderr to a log file, I risk combining output from SSH and output from the remote process on the host machine (that might send something to stderr): $ ssh -v somemachine 2 file.log So, I want to filter out only those lines that match "debug1": $ ssh -v somemachine | awk '/debug1/ {print "file.log"; next} {print}' Good so far, BUT ssh's debug output goes to stderr. So... $ ssh -v somemachine 2& | awk '/debug1/ {print "file.log"; next} {print}' Foiled again! I don't want to mix stdout and stderr. BAD! What does a kid like me do? I was about to go the route of named pipes or some such wildeness, but really, all I need to know is how to get awk to match patterns from stderr ONLY.

    Read the article

  • Python __import__ parameter confusion

    - by CMC
    I'm trying to import a module, while passing some global variables, but it does not seem to work: File test_1: test_2 = __import__("test_2", {"testvar": 1}) File test_2: print testvar This seems like it should work, and print a 1, but I get the following error when I run test_1: Traceback (most recent call last): File ".../test_1.py", line 1, in <module> print testvar NameError: name 'testvar' is not defined What am I doing wrong?

    Read the article

  • Web based printing from a Django application?

    - by lud0h
    Is there any recent developments in web based printing? I know using @media print in CSS, PDF based solution or iTextSharp but they are not really easy (except @media print) but alignment is little tricky if receipt contains barcodes or if I have to format for A5 etc., Is there anything new in HTML5 which will support this? I would like to print receipts from a Django based webapplication. Any tips? Thanks.

    Read the article

  • help merging perl code routines together for file processing

    - by jdamae
    I need some perl help in putting these (2) processes/code to work together. I was able to get them working individually to test, but I need help bringing them together especially with using the loop constructs. I'm not sure if I should go with foreach..anyways the code is below. Also, any best practices would be great too as I'm learning this language. Thanks for your help. Here's the process flow I am looking for: -read a directory -look for a particular file -use the file name to strip out some key information to create a newly processed file -process the input file -create the newly processed file for each input file read (if i read in 10, I create 10 new files) Sample Recs: col1,col2,col3,col4,col5 [email protected],[email protected],8,2009-09-24 21:00:46,1 [email protected],[email protected],16,2007-08-18 22:53:12,33 [email protected],[email protected],16,2007-08-18 23:41:23,33 Here's my test code: Target Filetype: `/backups/test/foo101.name.aue-foo_p002.20110124.csv` Part 1: my $target_dir = "/backups/test/"; opendir my $dh, $target_dir or die "can't opendir $target_dir: $!"; while (defined(my $file = readdir($dh))) { next if ($file =~ /^\.+$/); #Get filename attributes if ($file =~ /^foo(\d{3})\.name\.(\w{3})-foo_p(\d{1,4})\.\d+.csv$/) { print "$1\n"; print "$2\n"; print "$3\n"; } print "$file\n"; } Part 2: use strict; use Digest::MD5 qw(md5_hex); #Create new file open (NEWFILE, ">/backups/processed/foo$1.name.$2-foo_p$3.out") || die "cannot create file"; my $data = ''; my $line1 = <>; chomp $line1; my @heading = split /,/, $line1; my ($sep1, $sep2, $eorec) = ( "^A", "^E", "^D"); while (<>) { my $digest = md5_hex($data); chomp; my (@values) = split /,/; my $extra = "__mykey__$sep1$digest$sep2" ; $extra .= "$heading[$_]$sep1$values[$_]$sep2" for (0..scalar(@values)); $data .= "$extra$eorec"; print NEWFILE "$data"; } #print $data; close (NEWFILE);

    Read the article

  • Python Introspection: How to get varnames of class methods?

    - by daccle
    I want to get the names of the keyword arguments of the methods of a class. I think I understood how to get the names of the methods and how to get the variable names of a specific method, but I don't get how to combine these: class A(object): def A1(self, test1=None): self.test1 = test1 def A2(self, test2=None): self.test2 = test2 def A3(self): pass def A4(self, test4=None, test5=None): self.test4 = test4 self.test5 = test5 a = A() # to get the names of the methods: for methodname in a.__class__.__dict__.keys(): print methodname # to get the variable names of a specific method: for varname in a.A1.__func__.__code__.co_varnames: print varname # I want to have something like this: for function in class: print function.name for varname in function: print varname # desired output: A1 self test1 A2 self test2 A3 self A4 self test4 test5

    Read the article

  • How can I send email attachment without using an additional library in Perl?

    - by CheeseConQueso
    Hey, I was wondering if there is a way to attach files (specifically .csv files) to a mail message in Perl without using MIME::Lite or any other libraries. Right now, I have a 'mailer function' that works fine, but I'm not sure how to adapt it into attaching files. Here is what I have: open(MAIL, "|/usr/sbin/sendmail -t"); print MAIL "To: cheese\@yahoo.com\n"; print MAIL "From: queso\@what.com\n"; print MAIL "Subject: Attached is $filename\n\n"; print MAIL "$message"; close(MAIL); I think this is specific for UNIX.

    Read the article

  • How do I get javascript results using selenium?

    - by Seth
    I have the following code: from selenium import selenium selenium = selenium("localhost", 4444, "*chrome", "http://some_site.com/") selenium.start() sel = selenium sel.open("/") sel.type("ctl00_ContentPlaceHolder1_SuburbTownTextBox", "Adelaide,SA,5000") sel.click("ctl00_ContentPlaceHolder1_SearchImageButton") #text = sel.get_body_text() text = sel.get_html_source() print(text) The click executes a javascript file which then produces results on the same page. Obviously print(text) will only print the orignal html source. How do I get to the results of the javascript?

    Read the article

  • min() and max() give error: TypeError: 'float' object is not iterable

    - by PythonUser3.3
    markList=[] Lmark=0 Hmark=0 while True: mark=float(input("Enter your marks here(Click -1 to exit)")) if mark == -1: break markList.append(mark) markList.sort() mid = len(markList)//2 if len(markList)%2==0: median=(markList[mid]+ markList[mid-1])/2 print("Median:", median) else: print("Median:" , markList[mid]) Lmark==(min(mark)) print("The lowest mark is", Lmark) Hmark==(max(mark)) print("The highest mark is", Hmark) My program is a basic grade calculator using lists. My program asks the user to input their grades into a list in which it then calculates your average and finds your lowest and highest mark. I have found the average but I can't seem to figure out how to find the lowest and highest grade. Can you please show me pr tell me what to do?

    Read the article

  • linked list elements gone?

    - by Hristo
    I create a linked list dynamically and initialize the first node in main(), and I add to the list every time I spawn a worker process. Before the worker process exits, I print the list. Also, I print the list inside my sigchld signal handler. in main(): head = NULL; tail = NULL; // linked list to keep track of worker process dll_node_t *node; node = (dll_node_t *) malloc(sizeof(dll_node_t)); // initialize list, allocate memory append_node(node); node->pid = mainPID; // the first node is the MAIN process node->type = MAIN; in a fork()'d process: // add to list dll_node_t *node; node = (dll_node_t *) malloc(sizeof(dll_node_t)); append_node(node); node->pid = mmapFileWorkerStats->childPID; node->workerFileName = mmapFileWorkerStats->workerFileName; node->type = WORK; functions: void append_node(dll_node_t *nodeToAppend) { /* * append param node to end of list */ // if the list is empty if (head == NULL) { // create the first/head node head = nodeToAppend; nodeToAppend->prev = NULL; } else { tail->next = nodeToAppend; nodeToAppend->prev = tail; } // fix the tail to point to the new node tail = nodeToAppend; nodeToAppend->next = NULL; } finally... the signal handler: void chld_signalHandler() { dll_node_t *temp1 = head; while (temp1 != NULL) { printf("2. node's pid: %d\n", temp1->pid); temp1 = temp1->next; } int termChildPID = waitpid(-1, NULL, WNOHANG); dll_node_t *temp = head; while (temp != NULL) { if (temp->pid == termChildPID) { printf("found process: %d\n", temp->pid); } temp = temp->next; } return; } Is it true that upon the worker process exiting, the SIGCHLD signal handler is triggered? If so, that would mean that after I print the tree before exiting, the next thing I do is in the signal handler which is print the tree... which would mean i would print the tree twice? But the tree isn't the same. The node I add in the worker process doesn't exist when I print in the signal handler or at the very end of main(). Any idea why? Thanks, Hristo

    Read the article

  • how to create a dynamic sql statement w/ python and mysqldb

    - by Elias Bachaalany
    I have the following code: def sql_exec(self, sql_stmt, args = tuple()): """ Executes an SQL statement and returns a cursor. An SQL exception might be raised on error @return: SQL cursor object """ cursor = self.conn.cursor() if self.__debug_sql: try: print "sql_exec: " % (sql_stmt % args) except: print "sql_exec: " % sql_stmt cursor.execute(sql_stmt, args) return cursor def test(self, limit = 0): result = sql_exec(""" SELECT * FROM table """ + ("LIMIT %s" if limit else ""), (limit, )) while True: row = result.fetchone() if not row: break print row result.close() How can I nicely write test() so it works with or without 'limit' without having to write two queries?

    Read the article

  • Python csv reader acting weird

    - by PylonsN00b
    So OK if I run this wrong code: csvReader1 = csv.reader(file('new_categories.csv', "rU"), delimiter=',') for row1 in csvReader1: print row1[0] print row1[8] category_sku = str(row[8]) if category_sku == sku: classifications["Craft"] = row[0] classifications["Theme"] = row[1] I get: Knitting 391 Traceback (most recent call last): File "upload_all_inventory_ebay.py", line 403, in <module> inventory_item_list = get_item_list(product) File "upload_all_inventory_ebay.py", line 294, in get_item_list category_sku = str(row[8]) NameError: global name 'row' is not defined Where Knitting and 391 are exactly right, of course I need to refer to row[8] as row1[8]...k so I do this: csvReader1 = csv.reader(file('new_categories.csv', "rU"), delimiter=',') for row1 in csvReader1: print row1[0] print row1[8] category_sku = str(row1[8]) if category_sku == sku: classifications["Craft"] = row1[0] classifications["Theme"] = row1[1] And I get this: ........... Crochet 107452 Knitting 107454 Knitting 107455 Knitting 107456 Knitting 107457 Crochet 108200 Crochet 108201 Crochet 108205 Crochet 108213 Crochet 108214 Crochet 108217 108432 Quilt 108451 108482 108488 Scrapbooking 108711 Knitting 122363 Needlework Beading Crafts & Decorating Crochet Crochet Crochet Traceback (most recent call last): File "upload_all_inventory_ebay.py", line 403, in <module> inventory_item_list = get_item_list(product) File "upload_all_inventory_ebay.py", line 292, in get_item_list print row1[0] IndexError: list index out of range Where the output you see there is every effing thing in column 0 and column 1 !!!!!!!!!! Why? And WHY is row1[0] out of range if it wasn't before. YAY Fridays!

    Read the article

  • Python GUI does not update until entire process is finished

    - by ccwhite1
    I have a process that gets a files from a directory and puts them in a list. It then iterates that list in a loop. The last line of the loop being where it should update my gui display, then it begins the loop again with the next item in the list. My problem is that it does not actually update the gui until the entire process is complete, which depending on the size of the list could be 30 seconds to over a minute. This gives the feeling of the program being 'hung' What I wanted it to do was to process one line in the list, update the gui and then continue. Where did I go wrong? The line to update the list is # Populate listview with drive contents. The print statements are just for debug. def populateList(self): print "populateList" sSource = self.txSource.Value sDest = self.txDest.Value # re-intialize listview and validated list self.listView1.DeleteAllItems() self.validatedMove = None self.validatedMove = [] #Create list of files listOfFiles = getList(sSource) #prompt if no files detected if listOfFiles == []: self.lvActions.Append([datetime.datetime.now(),"Parse Source for .MP3 files","No .MP3 files in source directory"]) #Populate list after both Source and Dest are chosen if len(sDest) > 1 and len(sDest) > 1: print "-iterate listOfFiles" for file in listOfFiles: sFilename = os.path.basename(file) sTitle = getTitle(file) sArtist = getArtist(file) sAlbum = getAblum(file) # Make path = sDest + Artist + Album sDestDir = os.path.join (sDest, sArtist) sDestDir = os.path.join (sDestDir, sAlbum) #If file exists change destination to *.copyX.mp3 sDestDir = self.defineDestFilename(os.path.join(sDestDir,sFilename)) # Populate listview with drive contents self.listView1.Append([sFilename,sTitle,sArtist,sAlbum,sDestDir]) #populate list to later use in move command self.validatedMove.append([file,sDestDir]) print "-item added to SourceDest list" else: print "-list not iterated"

    Read the article

  • problem in printing fonts

    - by user1400
    hello i have a application on php that i show a report in the table , i want to print this page i can see my page fine in print preview , but when i send thuis page to printer ,the fonts are small and diffrent fonts that i set in css file this is my css file @page { size: A4 landscape; margin-top:2cm; margin-bottom:1cm; margin-left:1cm; margin-right:1cm; } table.print{ text-align:right; border:#999 1px solid; } table.print td.e1{ border-top:#999 1px solid; padding:5px 2px; text-align: right; font-size: 20pt; font-family:"stencil"; } table.print td.e2{ border-top:#999 1px solid; padding:5px 2px; text-align: right; font-size: 120%; font-family:"tahoma"; } thanks

    Read the article

  • how I can overcome this error C2679: binary '>>' : no operator found which takes a right-hand oper

    - by hussein abdullah
    #include <iostream> using std::cout; using std::cin; using std::endl; #include <cstring> void initialize(char[],int*); void input(const char[] ,int&); void print ( const char*,const int); void growOlder (const char [], int* ); bool comparePeople(const char* ,const int*,const char*,const int*); int main(){ char name1[25]; char name2[25]; int age1; int age2; initialize (name1,&age1); initialize (name2,&age2); print(name1,age1); print(name2,age2); input(name1,age1); input(name2,age2); print(name1,age1); print(name2,age2); growOlder(name2,&age2); if(comparePeople(name1,&age1,name2,&age2)) cout<<"Both People have the same name and age "<<endl; return 0; } void input(const char name[],int &age) { cout<<"Enter a name :"; cin>>name ; cout<<"Enter an age:"; cin>>age; cout<<endl; } void initialize ( char name[],int *age) { name[0]='\0'; *age=0; } void print ( const char name[],const int age ) { cout<<"The Value stored in variable name is :" <<name<<endl <<"The Value stored in variable age is :" <<age<<endl<<endl; } void growOlder(const char name[],int *age) { cout<< name <<" has grown one year older\n\n"; *age++; } bool comparePeople (const char *name1,const int *age1, const char *name2,const int *age2) { return(*age1==*age2 && !strcmp(name1,name2)); }

    Read the article

  • Indent or comment several text lines with VI

    - by Werner
    Hi, can vim or vim be used to comment or indent at the same time a number of lines? For instance: for item in Lista: ind = int(floor(1.0*(item-lmin)/width)) if ind==nintervals: ind=ind-1 print item,ind comment it to: #for item in Lista: #ind = int(floor(1.0*(item-lmin)/width)) #if ind==nintervals: #ind=ind-1 #print item,ind or indent it to: for item in Lista: ind = int(floor(1.0*(item-lmin)/width)) if ind==nintervals: ind=ind-1 print item,ind Thanks P.D. Is relevant the difference between VI and VIM?

    Read the article

  • Python singleton pattern

    - by Javier Garcia
    Hi, someone can tell me why this is incorrect as a singleton pattern: class preSingleton(object): def __call__(self): return self singleton = preSingleton() a = singleton() b = singleton() print a==b a.var_in_a = 100 b.var_in_b = 'hello' print a.var_in_b print b.var_in_a Edit: The above code prints: True hello 100 thank you very much

    Read the article

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