def main(): """ Entry point for the application script Call your main application code here """ if len(sys.argv) > 1: args = sys.argv[1] hello.hello(args)
def main(): import logging print("----") print("@", hello()) print("----") # basicConfig(level=logging.INFO, render=ltsvrender) basicConfig(level=logging.INFO) print("@", hello()) print("----") print("@", broken()) print("----")
def test(self): tests = ( ("John", "Hello, John!"), ("aLIce", "Hello, Alice!"), ("", "Hello, World!"), ) for inp, exp in tests: self.assertEqual(hello(inp), exp) self.assertEqual(hello(), "Hello, World!")
def annisa(): args = request.args if request.method == 'GET': if not len(args) is 0: if 'word' in args: response = hello(response, args['word']) return response
def application(environ, start_response): results = [] results.append(hello.hello()) helloWorld = hello.HelloWorld() results.append(helloWorld.sayHello()) output = "<br/>".join(results) # build the response body possibly using the environ dictionary response_body = output # HTTP response code and message status = '200 OK' # These are HTTP headers expected by the client. # They must be wrapped as a list of tupled pairs: # [(Header name, Header value)]. response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(response_body)))] # Send them to the server using the supplied function start_response(status, response_headers) # Return the response body. # Notice it is wrapped in a list although it could be any iterable. return [response_body]
def main(): print("Welcome to my code portfolio.\n") menu = "1.Largest Prime Factor Calculator\n" +"2.Shipping Calculator\n"+ \ "3.Cube Root Checker\n" + "4.Farenheit to Celsius Converter.\n" + \ "5.Improper Fraction Converter\n" + "6.Hello World\n" + \ "7.Multiple table with 42 highlighted \n" + \ "8.Random number Generator\n" + "9.Test Score Average Calculator \n" + \ "10.Program that adds all integers leading up to input \n" + \ "11.Fibonacci List \n" + "12.Two Number Division Checker\n" print(menu) selector = "" while selector != "q": selector = (input("\n Enter the number of the program to run or" + \ " q to quit")) if selector == "1": lgprime.lgprimefactor() elif selector == "2": shippingcalc.shippingcalc() elif selector == "3": cuberoot.cuberoot() elif selector == "4": farenheit.farenheitcalc() elif selector == "5": fractionconversion.fractionconversion() elif selector == "6": hello.hello() elif selector == "7": looper.looper() elif selector == "8": randnums.randNums() elif selector == "9": testcalc.testcalculator() elif selector == "10": adder.adder() elif selector == "11": fibonacci.fibonacciprinter() elif selector == "12": twonumber.twonumberdivision() elif selector == "m": print(menu) elif selector != "q": print("Oops, that is not a valid entry." + \ "Type m to bring up the menu again, " + \ "Type a program number or q to quit.") print("\nGoodbye and thanks for checking out my projects!")
def main(): print("Welcome to my code portfolio.\n") menu = "1.Largest Prime Factor Calculator\n" +"2.Shipping Calculator\n"+ \ "3.Cube Root Checker\n" + "4.Farenheit to Celsius Converter.\n" + \ "5.Improper Fraction Converter\n" + "6.Hello World\n" + \ "7.Multiple table with 42 highlighted \n" + \ "8.Random number Generator\n" + "9.Test Score Average Calculator \n" + \ "10.Program that adds all integers leading up to input \n" + \ "11.Fibonacci List \n" + "12.Two Number Division Checker\n" print (menu) selector = "" while selector != "q": selector = (input("\n Enter the number of the program to run or" + \ " q to quit")) if selector == "1": lgprime.lgprimefactor() elif selector == "2": shippingcalc.shippingcalc() elif selector == "3": cuberoot.cuberoot() elif selector == "4": farenheit.farenheitcalc() elif selector == "5": fractionconversion.fractionconversion() elif selector == "6": hello.hello() elif selector == "7": looper.looper() elif selector == "8": randnums.randNums() elif selector == "9": testcalc.testcalculator() elif selector == "10": adder.adder() elif selector == "11": fibonacci.fibonacciprinter() elif selector == "12": twonumber.twonumberdivision() elif selector =="m": print (menu) elif selector != "q": print("Oops, that is not a valid entry." + \ "Type m to bring up the menu again, " + \ "Type a program number or q to quit.") print("\nGoodbye and thanks for checking out my projects!")
def hello(self, who): ''' test ''' try: oracle = Oracle() return defer.succeed(hello(who))\ .addErrback(error, oracle)\ .addCallback(right, oracle) except Warning_: raise Warning_(getWarningInfo()) except Exception: raise Exception(getExcInfo())
def test_rand(self): from random import randint, choice NAMES = [ "James", "Christopher", "Ronald", "Mary", "Lisa", "Michelle", "John", "Daniel", "Anthony", "Patricia", "Nancy", "Laura", "Robert", "Paul", "Kevin", "Linda", "Karen", "Sarah", "Michael", "Mark", "Jason", "Barbara", "Betty", "Kimberly", "William", "Donald", "Jeff", "Elizabeth", "Helen", "Deborah", "David", "George", "Jennifer", "Sandra", "Richard", "Kenneth", "Maria", "Donna", "Charles", "Steven", "Susan", "Carol", "Joseph", "Edward", "Margaret", "Ruth", "Thomas", "Brian", "Dorothy", "Sharon", "" ] def create_test_case(): return "".join(c.lower() if randint(0, 200) % 3 else c.upper() for c in choice(NAMES)) reference = lambda n='', d='World': "Hello, %s!" % (n or d).title() for _ in range(100): test_case = create_test_case() self.assertEqual(hello(test_case), reference(test_case))
def main(): hello()
def test_is_string(self): s = hello.hello() self.assertTrue(isinstance(s, basestring)) self.assertEqual(s, 'Hello World') s = hello.hello('David') self.assertEqual(s, 'Hello David')
def test_hello_with_name(): """ If passed a name return 'hello {name}' """ assert hello.hello('Charlie') == 'Hello, Charlie'
def test_should_issue_hello_world_message(self): out = mock() hello(out) verify(out).write("Hello world of Python\n")
def test_hello(): got = hello("Christian") want = "Hello, Christian" assert got == want
def testHelloMsg(self): from hello import hello self.assertEqual(hello(), "Hello, world!")
def hello_world(language): """ A simple hello world function. """ print hello(language)
import hello print hello.hello() assert(hello.hello() == 'Hello World') print hello.hello_to_you("Max") try: print hello.hello_to_you(["Max"]) except TypeError, e: print 'Caught Type error %s' % repr(e)
def pretty(): sys.stdout.write('* ') hello.hello() sys.stdout.write(' *\n') %CALL_EXTERNAL_PRETTY%
def test(self): self.assertEquals(hello(),'Hello, world.')
def test_hello(self): name = "Bob" exp = "Hello, %s, nice to meet you!" % name self.assertEqual(hello(name), exp)
import sys sys.path.append("mymod.bmp") import hello hello.hello("Test test test!")
import hello print hello.hello()
import hello hello.hello('Henk',5);
def test_world(self): """sample test""" time.sleep(30) self.assertEqual(hello('wor'), 'hello wor')
import hello hello.hello("universe")
def main(): print("This is a main function") print hello.hello()
def menu(): """ The main menu """ while True: print(marvin_image) print( "Hi, I'm Robbie. I know almost all and will do my best to serve you. What can I do for you?" ) print("1) Present yourself to Marvin.") print("2) Convert C to F.") print("3) Word multiplication.") print("4) Calculate average.") print("5) Compare numbers.") print("6) Modify string.") print("7) Isogram.") print("8) Randomise string. ") print("9) Anagram. ") print("10) Akronom. ") print("11) Masking. ") print("12) Print current info. ") print("q) Quit.") choice = input("--> ") if choice == "q": print("Bye, bye - and welcome back anytime!") break elif "inv" in choice.lower(): print("\n", inv.inventory(choice)) elif "citat" in choice.lower(): print("\n", qu.readquote().rstrip()) elif "hej" in choice.lower(): print("\n", he.hello().rstrip()) elif "lunch" in choice.lower(): print("\n", he.lunch().rstrip()) elif choice == "1": ma.greeter() elif choice == "2": ma.temp_converter() elif choice == "3": ma.word_multiplier() elif choice == "4": ma.average_calc() elif choice == "5": ma.compare_numbers() elif choice == "6": ma.modify_string() elif choice == "7": ma.isogram() elif choice == "8": ma.randomise_string() elif choice == "9": ma.anagram() elif choice == "10": ma.akronom() elif choice == "11": ma.str_mask() elif choice == "12": ch12.choice_12() else: print( "\nThat is not a valid choice. You can only choose from the menu." ) input("\nPress enter to continue...")
def test_hello(self): 'test method' self.assertEqual(hello.hello(), 'Hello, ')
#!/usr/bin/env python import hello hello.hello('alabama') from threading import Thread t = [Thread(target=hello.waste_time) for _ in range(8)] map(Thread.start, t) map(Thread.join, t)
def sayHello(self): user = Users() return self.message + " - " + hello() + " - " + user.sayHello()
def sayHello(self): return self.message + " - " + hello()
# -*- coding: utf-8 -*- # @Author: lenovouser # @Date: 2019-06-16 22:00:01 # @Last Modified by: lenovouser # @Last Modified time: 2019-06-16 22:00:01 from hello import hello hello("lyric")
import sys sys.path.append('C:\Python34\Lib\mylib') import hello hello.hello() # hello,world! h
from hello import hello hello("Cython")
from hello import hello print(hello())
def test_hello(self): self.assertEqual("Hello World! I've greeted 0 times!", hello.hello()) self.assertEqual("Hello World! I've greeted 1 times!", hello.hello()) self.assertEqual("Hello World! I've greeted 2 times!", hello.hello())
from hello import hello import demo hello() demo.demo()
import hello hello.hello_world() hello.hello("ABC") def my_cb(arg): print("Callback called from c") print(f"{str(arg)}") hello.set_callback(my_cb) hello.call_cb() def set_str(my_str): my_str += "kucing" c = "" set_str(c) print(c) a = {} a[1] = "b" hello.set_dict(a) print(a["response"]) print("finish")
def test_default(self): self.assertEqual(hello.hello(), 'Hello, world!')
def test_world(self): """sample test""" self.assertEqual(hello('world'), 'hello world')
def test_customized(self): self.assertEqual(hello.hello('Joe'), 'Hello, Joe!')
def test_hello_no_name(): """ Checks if no name is passed we get hello world """ assert hello.hello() == 'Hello, world'
import hello print hello.hello('world!') assert hello.hello('world!') == 'hello, world!'
def test_world_unicode(self): """sample test with unicode""" self.assertEqual(hello(u'world'), u'hello world')
def test(app, watcher): x = app.fire(hello()) assert watcher.wait("hello") assert x.value == "Hello World!"
def main(): # getVersion() hello.hello()
def test_Hello(self): self.assertEqual('Hello World', hello.hello(), 'The world is quiet')
__pycache__目录:处理后的模块文件,以便快速再次导入模块. 模块具有作用域,在其中定义的类,函数,变量等都是模块的属性.模块是重用代码的重要方式 @author: 10841 """ import sys # 加入 path环境变量 sys.path.append(r'C:\Users\10841\Documents\Python Scripts\Python基础教程3') import hello import hello import importlib hello = importlib.reload(hello) # 重新导入模块,会再次执行,并替换掉之前的模块 hello.hello() import pprint # python解释器如何找到自己的模块 # 1.放到python解释器的目录下 pprint.pprint(sys.path) # python解释器寻找包的目录,一般将自己的包存在site-packages目录下 # 2.告诉解释器去指定的地方查找:将模块所在目录存于环境变量PYTHONPATH中即可 #================sys模块================= # 将命令行参数反序输出 print(sys.argv[0]) print(" ".join(reversed(sys.argv[1:]))) # argv[0]:脚本名称 #================os模块================= import os
def main(): politesse = hello.hello("Nicolas") politesse.SaysHello()
#!/usr/bin/env python -u import sys import os import hello import hello2 import drawing import drawing.colors from drawing import shapes import webbrowser hello.hello() print(hello.name) print hello2.hello() print(hello2.name) print print('PI = ' + str(drawing.PI)) print # sys.argv print('sys.argv:') for index, arg in enumerate(sys.argv): print(' ' + str(index) + ': ' + arg) # sys.modules
def test_hello_with_name(): assert hello("Foo") == 'Hello, Foo!'
def test_hello(): assert hello() == 'Hello world! Hi!' assert hello('Martians') == 'Hello Martians! Hi!'
def test_hello_without_name(): assert hello() == 'Hello!'
def pretty(): print '*', hello.hello() print '*' %CALL_EXTERNAL_PRETTY%
def test_hello(self): self.assertEqual("Hello!", hello())