Search Results

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

Page 108/782 | < Previous Page | 104 105 106 107 108 109 110 111 112 113 114 115  | Next Page >

  • php extending but with a new constructor...possible?

    - by Patrick
    I have a class: class test { function __construct() { print 'hello'; } function func_one() { print 'world'; } } what I would like to do is a have a class that sort of extends the test class. I say 'sort of', because the class needs to be able to run whatever function the test class is able to run, but NOT run the construct unless I ask it to. I do not want to override the construct. Anyone has any idea how to achieve this?

    Read the article

  • How to add a constructor to a subclassed numeric type?

    - by abbot
    I want to subclass a numeric type (say, int) in python and give it a shiny complex constructor. Something like this: class NamedInteger(int): def __init__(self, value): super(NamedInteger, self).__init__(value) self.name = 'pony' def __str__(self): return self.name x = NamedInteger(5) print x + 3 print str(x) This works fine under Python 2.4, but Python 2.6 gives a deprecation warning. What is the best way to subclass a numeric type and to redefine constructors for builtin types in newer Python versions?

    Read the article

  • Is there some way to make variables like $a and $b in regard to strict?

    - by Axeman
    In light of Michael Carman's comment, I have decided to rewrite the question. Note that 11 comments appear before this edit, and give credence to Michael's observation that I did not write the question in a way that made it clear what I was asking. Question: What is the standard--or cleanest way--to fake the special status that $a and $b have in regard to strict by simply importing a module? First of all some setup. The following works: #!/bin/perl use strict; print "\$a=$a\n"; print "\$b=$b\n"; If I add one more line: print "\$c=$c\n"; I get an error at compile time, which means that none of my dazzling print code gets to run. If I comment out use strict; it runs fine. Outside of strictures, $a and $b are mainly special in that sort passes the two values to be compared with those names. my @reverse_order = sort { $b <=> $a } @unsorted; Thus the main functional difference about $a and $b--even though Perl "knows their names"--is that you'd better know this when you sort, or use some of the functions in List::Util. It's only when you use strict, that $a and $b become special variables in a whole new way. They are the only variables that strict will pass over without complaining that they are not declared. : Now, I like strict, but it strikes me that if TIMTOWTDI (There is more than one way to do it) is Rule #1 in Perl, this is not very TIMTOWDI. It says that $a and $b are special and that's it. If you want to use variables you don't have to declare $a and $b are your guys. If you want to have three variables by adding $c, suddenly there's a whole other way to do it. Nevermind that in manipulating hashes $k and $v might make more sense: my %starts_upper_1_to_25 = skim { $k =~ m/^\p{IsUpper}/ && ( 1 <= $v && $v <= 25 ) } %my_hash ;` Now, I use and I like strict. But I just want $k and $v to be visible to skim for the most compact syntax. And I'd like it to be visible simply by use Hash::Helper qw<skim>; I'm not asking this question to know how to black-magic it. My "answer" below, should let you know that I know enough Perl to be dangerous. I'm asking if there is a way to make strict accept other variables, or what is the cleanest solution. The answer could well be no. If that's the case, it simply does not seem very TIMTOWTDI.

    Read the article

  • What happens when I instantiate class in Python?

    - by Konstantin
    Could you clarify some ideas behind Python classes and class instances? Consider this: class A(): name = 'A' a = A() a.name = 'B' # point 1 (instance of class A is used here) print a.name print A.name prints: B A if instead in point 1 I use class name, output is different: A.name = 'B' # point 1 (updated, class A itself is used here) prints: B B Even if classes in Python were some kind of prototype for class instances, I'd expect already created instances to remain intact, i.e. output like this: A B Can you explain what is actually going on?

    Read the article

  • perl, module variable

    - by Mike
    I don't really understand how scoping works in perl modules. This doesn't print anything. I would like it if running a.pl printed 1 b.pm $f=1; a.pl use b; print $f

    Read the article

  • Specifics of List Membership

    - by phasetwenty
    How does Python (2.6.4, specifically) determine list membership in general? I've run some tests to see what it does: def main(): obj = fancy_obj(arg='C:\\') needle = (50, obj) haystack = [(50, fancy_obj(arg='C:\\')), (1, obj,), needle] print (1, fancy_obj(arg='C:\\'),) in haystack print needle in haystack if __name__ == '__main__': main() Which yields: False True This tells me that Python is probably checking the object references, which makes sense. Is there something more definitive I can look at?

    Read the article

  • Unable to get set intersection to work

    - by chavanak
    Sorry for the double post, I will update this question if I can't get things to work :) I am trying to compare two files. I will list the two file content: File 1 File 2 "d.complex.1" "d.complex.1" 1 4 5 5 48 47 65 21 d.complex.10 d.complex.10 46 6 21 46 109 121 192 192 TI am trying to compare the contents of the two file but not in a trivial way. I will explain what I want with an example. If you observe the file content I have typed above, the d.complex.1 of file_1 has "5" similar to d.complex.1 in file_2; the same d.complex.1 in file_1 has nothing similar to d.complex.10 in file_2. What I am trying to do is just to print out those d.complex. which has nothing in similar with the other d.complex. Consider the d.complex. as a heading if you want. But all I am trying is compare the numbers below each d.complex. and if nothing matches, I want that particular d.complex. from both files to be printed. If even one number is present in both d.complex. of both files, I want it to be rejected. My Code: The method I chose to achieve this was to use sets and then do a difference. Code I wrote was: first_complex=open( "file1.txt", "r" ) first_complex_lines=first_complex.readlines() first_complex_lines=map( string.strip, first_complex_lines ) first_complex.close() second_complex=open( "file2.txt", "r" ) second_complex_lines=second_complex.readlines() second_complex_lines=map( string.strip, second_complex_lines ) second_complex.close() list_1=[] list_2=[] res_1=[] for line in first_complex_lines: if line.startswith( "d.complex" ): res_1.append( [] ) res_1[-1].append( line ) res_2=[] for line in second_complex_lines: if line.startswith( "d.complex" ): res_2.append( [] ) res_2[-1].append( line ) h=len( res_1 ) k=len( res_2 ) for i in res_1: for j in res_2: print i[0] print j[0] target_set=set ( i ) target_set_1=set( j ) for s in target_set: if s not in target_set_1: if s[0] != "d": print s The above code is giving an output like this (just an example): d.complex.1.dssp d.complex.1.dssp 1 48 65 d.complex.1.dssp d.complex.10.dssp 46 21 109 What I would like to have is: d.complex.1 d.complex.1 (name from file2) d.complex.1 d.complex.10 (name from file2) I am sorry for confusing you guys, but this is all that is required. I am so new to python so my concept above might be flawed. Also I have never used sets before :(. Can someone give me a hand here?

    Read the article

  • Merge decorator function as class

    - by SyetemHog
    How to make this merge function as class decorator? def merge(*arg, **kwarg): # get decorator args & kwargs def func(f): def tmp(*args, **kwargs): # get function args & kwargs kwargs.update(kwarg) # merge two dictionaries return f(*args, **kwargs) # return merged data return tmp return func Usage: @other_decorator # return *args and **kwarg @merge(list=['one','two','three']) # need to merge with @other_decorator def test(*a, **k): # get merged args and kwargs print 'args:', a print 'kwargs:', k

    Read the article

  • Python: for statement behavior

    - by BandGap
    Hi all. My question concerns the output of this statement: for x in range(4), y in range(4): print x print y Results in: [0, 1, 2, 3] 2 True 2 It seems there is a comparison involved, I just can't figure out why the output is structured like this.

    Read the article

  • Rewrite code from Threads to AnyEvent

    - by user1779868
    I wrote a code: use LWP::UserAgent; use HTTP::Cookies; use threads; use threads::shared; $| = 1; $threads = 50; my @urls : shared = loadf('url.txt'); my @thread_list = (); $thread_list[$_] = threads->create(\&thread) for 0 .. $threads - 1; $_->join for @thread_list; thread(); sub thread { my ($web, $ck) = browser(); while(1) { my $url = shift @urls; if(!$url) { last; } $code = $web->get($url)->code; print "[+] $url - code: $code\n"; if($code == 200) { open F, ">>200.txt"; print F $url."\n"; close F; } elsif($code == 301) { open F, ">>301.txt"; print F $url."\n"; close F; } else { open F, ">>else.txt"; print F "$url code - $code\n"; close F; } } } sub loadf { open (F, "<".$_[0]) or erroropen($_[0]); chomp(my @data = <F>); close F; return @data; } sub browser { my $web = new LWP::UserAgent; my $ck = new HTTP::Cookies; $web->cookie_jar($ck); $web->agent('Opera/9.80 (Windows 7; U; en) Presto/2.9.168 Version/11.50'); $web->timeout(5); return $web, $ck; } After its working for some time physical storage is full. Can u help me to re-write it with AnyEvent. I tried but my code didn't work. I read that it will help me to safe some memory. Thanks a lot to any helpers.

    Read the article

  • webprogramming -what is the learning pathway ?

    - by Bunny Rabbit
    i have some knowledge of css,jQuery,Grails,django,servlets and jsp still i can't see me designing good professional looking websites .what am lacking ? should i start learning jQUery ui ,should i get into adobe products like flash i am pretty confused. i am pretty bad in the userinterface part,

    Read the article

  • Enable "Current Page" in PrintDialog

    - by mizipzor
    Im using a System.Windows.Controls.PrintDialog to let the user print one or more pages from my application. This is what I currently got: PrintDialog printDialog = new PrintDialog(); printDialog.PageRangeSelection = PageRangeSelection.AllPages; printDialog.UserPageRangeEnabled = true; if (printDialog.ShowDialog() == true) { // do print ... } Im looking for the option to enable the Current Page radio button in the dialog. How to enable it?

    Read the article

  • Count numbers in words.

    - by bachchan
    I need an assembler 8080 software which counts words (delimited by space) which have more than two number in it. Example : this sh0uld b3 l1ke th1s would print : 0 words but Example : this sh0uld b3 l1k3 th1s f000k would print : 2 words <- word l1k3 contain number 1,3 and f000k number 0,0,0 the output should be displayer in hexadecimal format (optional)

    Read the article

  • Python new-style classes and __subclasses__ function

    - by Fraser Graham
    Can somebody explain to me why this works (in Python 2.5) : class Foo(object): pass class Bar(Foo): pass print(Foo.__subclasses__()) but this doesn't : class Foo(): pass class Bar(Foo): pass print(Foo.__subclasses__()) The latter returns "AttributeError: class Foo has no attribute '__subclasses__'" but i'm not sure why. I know this is related to old-style vs. new-style classes but i'm not clear on why that would make this functionality unavailable.

    Read the article

  • Perl, foreach order

    - by Mike
    Does Perl's foreach loop operator require that the list items be presented in order? For example my @a=(1,2,3); foreach my $item (@a) { print $item; } will always print 1 2 3? I suspect so, but I can't find it documented.

    Read the article

  • Perl ENV variable contains newline and tab

    - by Michael
    Say I have an environment variable myvar myvar=\tapple\n when the following command will print out this variable perl -e 'print "$ENV{myvar}"' I will literally have \tapple\n, however, I want those control chars to be evaluated and not escaped. How would I achieve it? In the real world $ENV residing in substitution, but I hope the answer will cover that.

    Read the article

< Previous Page | 104 105 106 107 108 109 110 111 112 113 114 115  | Next Page >