Search Results

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

Page 105/782 | < Previous Page | 101 102 103 104 105 106 107 108 109 110 111 112  | Next Page >

  • Format date in String Template email

    - by Gearóid
    I'm creating an email using String Template but when I print out a date, it prints out the full date (eg. Wed Apr 28 10:51:37 BST 2010). I'd like to print it out in the format dd/mm/yyyy but don't know how to format this in the .st file. I can't modify the date individually (using java's simpleDateFormatter) because I iterate over a collection of objects with dates. Is there a way to format the date in the .st email template?

    Read the article

  • python return class

    - by William P
    Hi I new to python and I read from someone else of the example code below: class A: def current(self): data = Data(a=a,b=b,c=c) return data class B(A): #something here #print data a b c How do I print out the data a, b, and c?

    Read the article

  • Generate a list of file names based on month and year arithmetic

    - by MacUsers
    How can I list the numbers 01 to 12 (one for each of the 12 months) in such a way so that the current month always comes last where the oldest one is first. In other words, if the number is grater than the current month, it's from the previous year. e.g. 02 is Feb, 2011 (the current month right now), 03 is March, 2010 and 09 is Sep, 2010 but 01 is Jan, 2011. In this case, I'd like to have [09, 03, 01, 02]. This is what I'm doing to determine the year: for inFile in os.listdir('.'): if inFile.isdigit(): month = months[int(inFile)] if int(inFile) <= int(strftime("%m")): year = strftime("%Y") else: year = int(strftime("%Y"))-1 mnYear = month + ", " + str(year) I don't have a clue what to do next. What should I do here? Update: I think, I better upload the entire script for better understanding. #!/usr/bin/env python import os, sys from time import strftime from calendar import month_abbr vGroup = {} vo = "group_lhcb" SI00_fig = float(2.478) months = tuple(month_abbr) print "\n%-12s\t%10s\t%8s\t%10s" % ('VOs','CPU-time','CPU-time','kSI2K-hrs') print "%-12s\t%10s\t%8s\t%10s" % ('','(in Sec)','(in Hrs)','(*2.478)') print "=" * 58 for inFile in os.listdir('.'): if inFile.isdigit(): readFile = open(inFile, 'r') lines = readFile.readlines() readFile.close() month = months[int(inFile)] if int(inFile) <= int(strftime("%m")): year = strftime("%Y") else: year = int(strftime("%Y"))-1 mnYear = month + ", " + str(year) for line in lines[2:]: if line.find(vo)==0: g, i = line.split() s = vGroup.get(g, 0) vGroup[g] = s + int(i) sumHrs = ((vGroup[g]/60)/60) sumSi2k = sumHrs*SI00_fig print "%-12s\t%10s\t%8s\t%10.2f" % (mnYear,vGroup[g],sumHrs,sumSi2k) del vGroup[g] When I run the script, I get this: [root@serv07 usage]# ./test.py VOs CPU-time CPU-time kSI2K-hrs (in Sec) (in Hrs) (*2.478) ================================================== Jan, 2011 211201372 58667 145376.83 Dec, 2010 5064337 1406 3484.07 Feb, 2011 17506049 4862 12048.04 Sep, 2010 210874275 58576 145151.33 As I said in the original post, I like the result to be in this order instead: Sep, 2010 210874275 58576 145151.33 Dec, 2010 5064337 1406 3484.07 Jan, 2011 211201372 58667 145376.83 Feb, 2011 17506049 4862 12048.04 The files in the source directory reads like this: [root@serv07 usage]# ls -l total 3632 -rw-r--r-- 1 root root 1144972 Feb 9 19:23 01 -rw-r--r-- 1 root root 556630 Feb 13 09:11 02 -rw-r--r-- 1 root root 443782 Feb 11 17:23 02.bak -rw-r--r-- 1 root root 1144556 Feb 14 09:30 09 -rw-r--r-- 1 root root 370822 Feb 9 19:24 12 Did I give a better picture now? Sorry for not being very clear in the first place. Cheers!! Update @Mark Ransom This is the result from Mark's suggestion: [root@serv07 usage]# ./test.py VOs CPU-time CPU-time kSI2K-hrs (in Sec) (in Hrs) (*2.478) ========================================================== Dec, 2010 5064337 1406 3484.07 Sep, 2010 210874275 58576 145151.33 Feb, 2011 17506049 4862 12048.04 Jan, 2011 211201372 58667 145376.83 As I said before, I'm looking for the result to b printed in this order: Sep, 2010 - Dec, 2010 - Jan, 2011 - Feb, 2011 Cheers!!

    Read the article

  • Simaltaneous connections with PHP and SOAP?

    - by Dov
    I'm new to using SOAP and understanding the utmost basics of it. I create a client resource/connection, I then run some queries in a loop and I'm done. The issue I am having is when I increase the iterations of the loop, ie: from 100 to 1000, it seems to run out of memory and drops an internal server error. How could I possibly run either a) multiple simaltaneous connections or b) create a connection, 100 iterations, close connection, create connection.. etc. "a)" looks to be the better option but I have no clue as to how to get it up and running whilst keeping memory (I assume opening and closing connections) at a minimum. Thanks in advance! index.php <?php // set loops to 0 $loops = 0; // connection credentials and settings $location = 'https://theconsole.com/'; $wsdl = $location.'?wsdl'; $username = 'user'; $password = 'pass'; // include the console and client classes include "class_console.php"; include "class_client.php"; // create a client resource / connection $client = new Client($location, $wsdl, $username, $password); while ($loops <= 100) { $dostuff; } ?> class_console.php <?php class Console { // the connection resource private $connection = NULL; /** * When this object is instantiated a connection will be made to the console */ public function __construct($location, $wsdl, $username, $password, $proxyHost = NULL, $proxyPort = NULL) { if(is_null($proxyHost) || is_null($proxyPort)) $connection = new SoapClient($wsdl, array('login' => $username, 'password' => $password)); else $connection = new SoapClient($wsdl, array('login' => $username, 'password' => $password, 'proxy_host' => $proxyHost, 'proxy_port' => $proxyPort)); $connection->__setLocation($location); $this->connection = $connection; return $this->connection; } /** * Will print any type of data to screen, where supported by print_r * * @param $var - The data to print to screen * @return $this->connection - The connection resource **/ public function screen($var) { print '<pre>'; print_r($var); print '</pre>'; return $this->connection; } /** * Returns a server / connection resource * * @return $this->connection - The connection resource */ public function srv() { return $this->connection; } } ?>

    Read the article

  • use of system.exit(0)

    - by Warrior
    public class WrapperTest { static { print(10); } static void print(int x) { System.out.println(x); System.exit(0); } } In the above code System.exit(0) is used to stop the program. What argument does that method take? Why do we gave it as 0. Can anyone explain the concept?Thanks.

    Read the article

  • Automatically open files given as command line arguments in Python

    - by mk
    I have a lot of Perl scripts that looks something like the following. What it does is that it will automatically open any file given as a command line argument and in this case print the content of that file. If no file is given it will instead read from standard input. while ( <> ) { print $_; } Is there a way to do something similar in Python without having to explicitly open each file?

    Read the article

  • How to show why "try" failed in python

    - by calccrypto
    is there anyway to show why a "try" failed, and skipped to "except", without writing out all the possible errors by hand, and without ending the program? example: try: 1/0 except: someway to show "Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> 1/0 ZeroDivisionError: integer division or modulo by zero" i dont want to doif:print error 1, elif: print error 2, elif: etc.... i want to see the error that would be shown had try not been there

    Read the article

  • splat operator in groovy?

    - by IttayD
    def foo(map, name) { println(map) } foo("bar", hi: "bye") will print [hi:bye] Now I have a previous map that I wish to pass along to foo. In pseudo code, something like: def otherMap = [hi: "world"] foo("bar", hi: "bye", otherMap*) So that it prints [hi:world] This doesn't work of course. Also, trying to pass just the map mixes the order of arguments: def otherMap = [hi: "world"] foo("bar", otherMap) will print bar How can I fix this?

    Read the article

  • How can I get the name of the current subroutine in Perl?

    - by kiruthika
    In Perl we can get the name of the current package and current line number Using the predefined variables like __PACKAGE__ and __LINE__. Like this I want to get the name of the current subroutine: use strict; use warnings; print __PACKAGE__; sub test() { print __LINE__; } &test(); In the above code I want to get the name of the subroutine inside the function test.

    Read the article

  • php class extend - run something before running parent function

    - by Patrick
    Hi, say I have this class: class animal { function noise() { print 'woof'; } function move() { print 'moved'; } } class dog extends animal { } What I would like to do is when i run $dog-noise() or $dog-move(), it would run something first prior to calling animal class's noise/move. Is this doable? Like maybe logging the function call. If not with class extend, what else can I use to achieve this? Thank you!

    Read the article

  • Implementing a command line in perl

    - by abubacker
    I used Term::shellUI module and almost every thing is working as expected but the issue is when I pressed ctrl+c I want to print "Please use ctrl+d to exit the shell" , for that I handle the signal but the message print only after I pressed the new line how to resolve this ! Thanks in advance !

    Read the article

  • Disable printing in adobe Flex

    - by Ankur Chauhan
    I am building my website in adobe flex(i am n00b). I have some photographs which I would like to make sure that people cannot print. I do understand that it is not possible to completely stop users from printing. But atleast disable the context menu or just the print option and the copy option. Any and all things about this is helpful

    Read the article

  • How do I forward a request to a different url in python

    - by tax
    import SimpleHTTPServer import SocketServer class myHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): print self.path if self.path == '/analog': return "http://someserver.com/analog" return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) theport = 1234 Handler = myHandler pywebserver = SocketServer.TCPServer(("", theport), Handler) print "Python based web server. Serving at port", theport pywebserver.serve_forever()

    Read the article

  • MySQL error problem

    - by comma
    I keep getting the error listed below but it only says line 1 what does this mean and how do I fix it? Here is the error I keep getting? You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 here is the code. if (isset($_POST['info_submitted'])) { $user_id = '5'; $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $dbc = mysqli_query($mysqli,"SELECT learned_skills.*, users_skills.* FROM learned_skills INNER JOIN users_skills ON learned_skills.id = users_skills.skill_id WHERE user_id='$user_id'"); $skill = $_POST['skill']; $experience = $_POST['experience']; $year = $_POST['year']; if (mysqli_num_rows($dbc) == 0) { $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $query1 = mysqli_query($mysqli,"INSERT INTO learned_skills (skill, experience, year) VALUES ('" . $skill . "', '" . $experience . "', '" . $year . "')"); } if (!mysqli_query($mysqli, $query1)) { print mysqli_error($mysqli); return; } $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $dbc = mysqli_query($mysqli,"SELECT id FROM learned_skills WHERE id='" . $skill . "' AND experience='" . $experience . "' AND year='" . $year . "'"); if (!$dbc) { print mysqli_error($mysqli); } else { while($row = mysqli_fetch_array($dbc)){ $id = $row["id"]; } } $query2 = "INSERT INTO users_skills (skill_id, user_id, date_created) VALUES ('$id', '$user_id', NOW())"; if (!mysqli_query($mysqli, $query2)) { print mysqli_error($mysqli); return; } if ($dbc == TRUE) { $dbc = mysqli_query($mysqli,"UPDATE learned_skills JOIN users_skills ON (users_skills.skill_id = learned_skills.id) SET skill = '$skill', experience = '$experience', year = '$year'"); echo '<p class="changes-saved">Your changes have been saved!</p>'; } if (!$dbc) { print mysqli_error($mysqli); return; } }

    Read the article

  • I'm writing a spellchecking program, how do I replace ch in a string?

    - by Ajay Hopkins
    What am I doing wrong/what can I do? import sys import string def remove(file): punctuation = string.punctuation for ch in file: if len(ch) > 1: print('error - ch is larger than 1 --| {0} |--'.format(ch)) if ch in punctuation: ch = ' ' return ch else: return ch ref = (open("ref.txt","r")) test_file = (open("test.txt", "r")) dictionary = ref.read().split() file = test_file.read().lower() file = remove(file) print(file) This is in Python 3.1.2

    Read the article

  • python: strip comma end of string

    - by krisdigitx
    how do i strip comma from the end of an string, i tried awk = subprocess.Popen([r"awk", "{print $10}"], stdin=subprocess.PIPE) awk_stdin = awk.communicate(uptime_stdout)[0] print awk_stdin temp = awk_stdin t = temp.strip(",") also tried t = temp.rstrip(","), both don't work.

    Read the article

  • overwrite existing entity via bulkloader.Loader

    - by Ray Yun
    I was going to CSV based export/import for large data with app engine. My idea was just simple. First column of CSV would be key of entity. If it's not empty, that row means existing entity and should overwrite old one. Else, that row is new entity and should create new one. I could export key of entity by adding key property. class FrontExporter(bulkloader.Exporter): def __init__(self): bulkloader.Exporter.__init__(self, 'Front', [ ('__key__', str, None), ('name', str, None), ]) But when I was trying to upload CSV, it had failed because bulkloader.Loader.generate_key() was just for "key_name" not "key" itself. That means all exported entities in CSV should have unique 'key_name' if I want to modify-and-reupload them. class FrontLoader(bulkloader.Loader): def __init__(self): bulkloader.Loader.__init__(self, 'Front', [ ('_UNUSED', lambda x: None), ('name', lambda x: x.decode('utf-8')), ]) def generate_key(self,i,values): # first column is key keystr = values[0] if len(keystr)==0: return None return keystr I also tried to load key directly without using generate_key(), but both failed. class FrontLoader(bulkloader.Loader): def __init__(self): bulkloader.Loader.__init__(self, 'Front', [ ('Key', db.Key), # not working. just create new one. ('__key__', db.Key), # same... So, how can I overwrite existing entity which has no 'key_name'? It would be horrible if I should give unique name to all entities..... From the first answer, I could handle this problem. :) def create_entity(self, values, key_name=None, parent=None): # if key_name is None: # print 'key_name is None' # else: # print 'key_name=<',key_name,'> : length=',len(key_name) Validate(values, (list, tuple)) assert len(values) == len(self._Loader__properties), ( 'Expected %d columns, found %d.' % (len(self._Loader__properties), len(values))) model_class = GetImplementationClass(self.kind) properties = { 'key_name': key_name, 'parent': parent, } for (name, converter), val in zip(self._Loader__properties, values): if converter is bool and val.lower() in ('0', 'false', 'no'): val = False properties[name] = converter(val) if key_name is None: entity = model_class(**properties) #print 'create new one' else: entity = model_class.get(key_name) for key, value in properties.items(): setattr(entity, key, value) #print 'overwrite old one' entities = self.handle_entity(entity) if entities: if not isinstance(entities, (list, tuple)): entities = [entities] for entity in entities: if not isinstance(entity, db.Model): raise TypeError('Expected a db.Model, received %s (a %s).' % (entity, entity.__class__)) return entities def generate_key(self,i,values): # first column is key if values[0] is None or values[0] in ('',' ','-','.'): return None return values[0]

    Read the article

  • Change array that might contain None to an array that contains "" in python

    - by vy32
    I have a python function that gets an array called row. Typically row contains things like: ["Hello","goodbye","green"] And I print it with: print "\t".join(row) Unfortunately, sometimes it contains: ["Hello",None,"green"] Which generates this error: TypeError: sequence item 2: expected string or Unicode, NoneType found Is there an easy way to replace any None elements with ""?

    Read the article

  • vi script problem on autocmd

    - by schemacs
    I want to create a template for all my python scripts using this autocmd bufnewfile *.py so ~/.vim/templates/python_skeleton.txt the content of python_sekleton.txt is as simple as this: #!/usr/bin/python # -*- coding: utf-8 -*- print 'Hello World' but vi give error message when i start to edit a new python script: line 2: E488: Trailing characters: # -*- coding: utf-8 -*- line 4: E488: Trailing characters: print 'Hello World' it seems '#' is not escaped,and anyone can work it out?thanks i advance

    Read the article

  • How to fix this python program?

    - by Phenom
    import math def p(n): return 393000*((288200/393000)^n * math.exp(-(288200/393000)))/math.factorial(n) print p(3) When I run it, I get the following error message: Traceback (most recent call last): File "poisson.py", line 6, in <module> print p(3) File "poisson.py", line 4, in p return 393000*((288200/393000)^n * math.exp(-(288200/393000)))/math.factoria l(n) TypeError: unsupported operand type(s) for ^: 'int' and 'float'

    Read the article

  • Where does a Server trigger save in SQL Server?

    - by Mostafa
    A couple of days ago , I was practicing and I wrote some triggers like these : create trigger trg_preventionDrop on all server for drop_database as print 'Can not Drop Database' rollback tran go create trigger trg_preventDeleteTable on database for drop_table as print 'you can not delete any table' rollback tran But the problem is I don't know where it has saved and How can I delete or edit those. Thank you

    Read the article

< Previous Page | 101 102 103 104 105 106 107 108 109 110 111 112  | Next Page >