The execution environment for Python-based learning code

Source: Internet
Author: User
Class C (object): Def __call__ (self, *args, **kwargs): print "I ' m callable! Called with args:\n ", ARGSC = C () C (' A ', 1) single_code = Compile (" print ' hello,world! ' "," ', ' single ') exec (Single_code) Eval_code = Compile (' 100*3 ', ' ', ' eval ') print eval (eval_code) #exec_code = Compile ("" "req = input (' input: ') #for eachnum in    Range (req): # Print Eachnum "" "," ', ' exec ') #exec (exec_code) Exec "" "x = 0print ' x is currently: ', Xwhile x < 5:x+=1 print ' incrementing x to: ', X "" "#f = Open (' c14.py ') #exec f#print F.tell () #print f.close () #from os.path import GetSize  #getsize (' c14.py ') #f. Seek (0) #exec f#loopmakedashes = ' \ n ' + '-' * 50exec_dict = {' F ': ' "" for%s in%s:print %s "" ", ' s ':" ""%s = 0%s =%s while%s < Len (%s): Print%s[%s]%s =%s + 1 "" ", ' N ':" "" "%s =%d while%s <%d:print%s%s =%s +%d" ""}def Main (): Ltype = Raw_input (' Loop type?[ For/while] ') Dtype = Raw_input (' Data type?[ NUMBER/SEQ] ' if dtype = = ' n ': start = input (' Start value?: ') stop = input (' Ending value?: ') Step = Input (' steping value?: ') seq = str (range (start,stop,step)) def foo (): Return Truedef bar (): ' Bar () does not M Uch ' return truefoo.__doc__ = ' foo () does not much ' Foo.tester = "" "If Foo (): print ' passed ' else:print ' failed '" "            "For Eachattr in Dir (): obj = eval (eachattr) if Isinstance (Obj,type (foo)): If Hasattr (obj, ' __doc__ '): print ' \nfunction '%s ' has a doc string:\n\t%s '% (eachattr,obj.__doc__) if hasattr (obj, ' tester '): P  Rint ' \nfunction '%s ' have tester '% eachattr exec (obj.tester) Else:print '%s function has no  Tester '% eachattr else:print '%s is not a function '% eachattrimport os#print os.system (' ping www.qq.com ') F = Os.popen (' dir ') data = F.readlines () f.close () print data## replace Os.systemfrom subprocess Import callres = Call (' dir '), Shell =true) # # replace Os.popenfrom subprocess Import Pipe,popenf = Popen ((' WMIC ', ' diskdrive '), stdout=pipe). Stdoutdata = F.readlines () f.close () print    DataImport sysdef usage (): print ' At least 2 arguments ' print ' usage:args.py arg1 arg2 [Arg3 ...] Sys.exit (1) argc = Len (sys.argv) #if argc < 3:# usage () Prev_exit_func = getattr (sys, ' exitfunc ', None) def my_exit_func (o Ld_exit=prev_exit_func): If Old_exit is not None and callable (old_exit): Old_exit () Sys.exitfunc = My_exi T_funcdef my_exit (): print ' exit python ' sys.exitfunc = My_exitprint ' Hello,begin exit. ' Sys.exit (1)

The above is the Python Basic Learning Code Execution Environment content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.