亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? python for newbies.htm

?? a collection of mega hacking tools
?? HTM
?? 第 1 頁 / 共 4 頁
字號(hào):
Finally, an example: <PRE>&gt;&gt;&gt; f.readlines() #Our imaginary file; create it if you want

['This is the first line\012', 'This is the second line\012', "Hmm I'm running out

of creative things to say\012", 'Alright, this is the last line']

&gt;&gt;&gt; f.seek(0) #You need this to go back to the beginning of the file; see below

&gt;&gt;&gt; f.readline()

'This is the first line\012'

</PRE>Just in case you're wondering, the \012 at the end of every line is just a 

newline. When reading files, Python replaces simple \ characters like \n with 

their hex (ASCII) code. If you didn't get that, just remember that \012's are 

really \n's. There are three (maybe four) more important methods of files. 

First, read and seek. read just reads the entire file into a string, or a 

maximum number of bytes if you specify it. seek needs one argument, which is the 

offset in the file to go to, or seek. Huh? Well, Python reads files by putting a 

little pointer in one and moving it along. When you read from a file, the little 

pointer moves along to the end of the part you read. If you read again, it'll 

start from where the pointer left off. seek will tell the pointer to go back (or 

forward) to a specified point in the file. Here's another example, using the 

same imaginary file as above: <PRE>&gt;&gt;&gt; f.seek(12) #Offsets start at 0, therefore 12 is 'f'

&gt;&gt;&gt; f.read(10)

'first line'

&gt;&gt;&gt; f.seek(0)

&gt;&gt;&gt; f.read() #Whole file. You probably shouldn't do this with big files.

"This is the first line\012This is the second line\012Hmm I'm running out

of creative things to say\012Alright, this is the last line"

</PRE>Then, finally, there is the write function, which (surprise!) writes to 

your file. Just put in the parentheses the string you want to write. Be sure you 

have a file opened in mode w, r+, or a, though! Also, if you want to create a 

new file you must use the mode w or a, not r+. The last method is close, which 

closes the file and frees up any memory it's been using. It's always good 

programming practice to close any files when you're done with them or before you 

leave. One last example for this section, then we move on: <PRE>&gt;&gt;&gt; f = open( "mynewfile.txt", "w" )

&gt;&gt;&gt; f.write( "This is some text" )

&gt;&gt;&gt; f.close()

&gt;&gt;&gt; f.read() #Oops! Can't read a closed file (or a write-only file for that matter)

Traceback (most recent call last):

  File "&lt;stdin&gt;", line 1, in ?

ValueError: I/O operation on closed file

&gt;&gt;&gt; f = open( "mynewfile.txt" )

&gt;&gt;&gt; f.read()

'This is some text'

</PRE>

<P></P>

<P><FONT size=-2><A 

href="#top">Back 

to top</A></FONT></P>

<HR>



<H2 align=center><A name=mod>Modules</A></H2>

<H3 align=center><A name=mod1>Overview and Importing</A></H3>

<P>Before we talk about Python's wide variety of builtin modules, let's go over 

what a module is first and how to get to them. A module is a script (or compiled 

library) that can be loaded into the interpreter environment separately from the 

core language of Python. Modules are accessed with the import statement, which 

can be used in a number of ways: <PRE>&gt;&gt;&gt; import sys #For these examples we're using the builtin sys module

&gt;&gt;&gt; sys.argv #Access names from the modules like you would an object

['']

&gt;&gt;&gt; from sys import argv #Another way to call it

&gt;&gt;&gt; argv

['']

&gt;&gt;&gt; from sys import * #Get everything in the sys module

&gt;&gt;&gt; stdout

&lt;open file '&lt;stdout&gt;', mode 'w' at 0x80d34b0&gt;

</PRE>Confusing? Not really. Let's go through it. The first line imports the 

module sys (one of the <A 

href="#builtin">builtin 

modules</A>). Notice on the next line that we needed to call a member of sys, 

argv (the arguments passed to the interpreter), with a . like we did for 

objects. This is using the so-called sys namespace, i.e. all sys members are 

accessed using, obviously, the name 'sys'. Alternatively, if we put 'from 

&lt;module&gt; import &lt;members&gt;', we use the global namespace. Then you 

can access the method's members just like any other sort of local variables or 

base functions. If you want to use the whole module in the global namespace, 

just do a 'from &lt;module&gt; import *'. Not too hard, eh? 

<P></P>

<P><FONT size=-2><A 

href="#top">Back 

to top</A></FONT></P>

<HR>



<H3 align=center><A name=builtin>Builtin Modules</A></H3>

<P>Python, being the versatile language it is, has a large selection of modules 

built into the default distribution. And I do mean large: at my count, there are 

196 modules available in Python 2.0 (including obsolete and OS-specific ones). 

When I say "builtin," this doesn't mean you don't have to import them, just that 

they should be included in Python installation. So, I'll list a choice 5 or so 

here, with basic descriptions of what they do and only a few of their members. 

</P>

<UL>

  <LI><B><FONT size=+1>sys</FONT></B> - Basic system/program functions 

  <UL>

    <LI><B>argv</B> - List of commands passed to the interpreter 

    <LI><B>stdout, stdin, stderr</B> - Basic standard output, standard input, 

    and standard error. These can be accessed like normal files. 

    <LI><B>exit</B> - Exits the program gracefully, accepting a value as the 

    exit code (basically 0=good exit, non-0=error) 

    <LI><B>path</B> - The paths Python looks in to find modules to import 

  </LI></UL>

  <LI><B><FONT size=+1>math</FONT></B> - Mathematical functions and constants. I 

  won't list them all here, but math contains many functions like sin, acos, 

  tanh, log, etc. Here are the constants: 

  <UL>

    <LI><B>pi</B> - The mathematical constant &#960;. The ratio of a circle's 

    diameter to its circumference, approximately 3.1415926535897931 

    <LI><B>e</B> - The base of the natural logarithm (ln). Get it with the sum 

    of 1/k! for all numbers k 0-&gt;infinity. Oddly enough, factorials (and 

    infinity) are not in the math module. </LI></UL>

  <LI><B><FONT size=+1>string</FONT></B> - Functions for more manipulations of 

  strings 

  <UL>

    <LI><B>printable</B> - A string of all so-called printable characters. Also 

    available are digits, letters (uppercase and lowercase), whitespace, and 

    punctuation. 

    <LI><B>atoi, atof, atol</B> - Convert strings to int, float, and long, 

    respectively. In Python 2.0 you should use builtins functions int, float, 

    and long. 

    <LI><B>find</B> - Find the lowest index where the second string (argument) 

    appears in the first. 

    <LI><B>count</B> - Count the number of times the second string appears in 

    the first. 

    <LI><B>split</B> - Split the string given in the first argument by 

    whitespace characters; return a list. If a second argument is given, the 

    string is split according to that instead of whitespace. 

    <LI><B>strip</B> - Strip leading and trailing whitespace from the given 

    string. 

    <LI><B>replace</B> - Replace all occurrences of the second string in the 

    first string with the third string. Err, look at it this way: replace( str, 

    "old", "new" ) replaces all occurrences of "old" in str with "new". </LI></UL>

  <LI><B><FONT size=+1>random</FONT></B> 

  <UL>

    <LI><B>seed</B> - Seeds the random number generator with three optional 

    arguments; defaults to the current time 

    <LI><B>random</B> - Returns the next random number as a floating-point 

    number between 0 and 1. 

    <LI><B>randint</B> - Returns a random number between two given integers. 

    <LI><B>uniform</B> - Same as randint, only with floating-point numbers. 

    <LI><B>choice</B> - Randomly chooses an element from the specified list or 

    tuple. </LI></UL>

  <LI><B><FONT size=+1>time</FONT></B> - Functions for getting and manipulating 

  local and arbitrary times. See the Python library documentation for more 

  complete information. 

  <UL>

    <LI><B>time</B> - No arguments, returns a long number that's your system's 

    current time, in seconds since...some time. Not really useful without some 

    sort of parser, except for seeding randoms. 

    <LI><B>localtime</B> - A parser. Given a time (like that returned by the 

    time function), it returns a tuple with the following information: year 

    (four-digit), month (1-12), day (1-31), hour (0-23), minute (0-59), second 

    (0-61 - 60 &amp; 61 for leap seconds, never used), weekday (0-6, Monday is 

    0), day (1-366), daylight savings time (0 - no, 1 - yes, -1 - system 

    default). Useful :) 

    <LI><B>gmtime</B> - Same as above, except in Greenwich Mean Time, not your 

    system's local time. 

    <LI><B>asctime</B> - Given a tuple from localtime or gmtime, returns a 

    string in the format 'Thu Mar 22 18:24:35 2001'. </LI></UL>

  <LI><B><FONT size=+1>re</FONT></B> - Regular expression (regexp) operators. I 

  won't cover them here, but I thought all you Perl fans out there might like to 

  know they exist in Python. There are some definite peculiarities about regexps 

  in Python, so read the docs...docs are your friends :). </LI></UL>

<P><FONT size=-2><A 

href="#top">Back 

to top</A></FONT></P>

<HR>



<H3 align=center><A name=yours>User-Defined Modules and Functions</A></H3>

<P>Of course, what use are all these modules if you can't use your own? Well, a 

user-defined module is just a .py file in one of Python's module directories. To 

import the module, it's run, and any functions, variables, classes, etc. are 

imported in. You can specify what to import, just like for any other module. 

Well, then, that's all well and good, but a big part of these modules is 

functions. How to make your own functions, then? Ok. </P>

<P>Alright. So we want a function. Since I like math, we'll do a simple 

logarithm to any base using the log function in the math module. Here we go, try 

this: <PRE>&gt;&gt;&gt; def logb( b, n ):

...   from math import log

...   a = log(n)/log(b)

...   if a - int(a) == 0: #a is an int

...     return int(a)

...   else:

...     return a

...

</PRE>How nice. Only a couple things should need explaining, unless you haven't 

taken high school algebra (hey no offense...I'm just a freshman :). This 'def' 

thing? Well, it's just the name of the function and the arguments it takes. I 

should hope you have a good idea of what arguments are now. Then there's return. 

It's...uh...what the function returns :). Execution stops after a return 

statemnt, just like a break statement. Except it returns something. Ok. Well, 

I've kinda run out of things to say...so here's an example module, just for 

practice. Hey, this is a tutorial, isn't it? Let's go, put this in moremath.py: <PRE>#!/usr/bin/python



def logb( b, n ): #Definition

  from math import log #Need this!

  a = log(n)/log(b) #Change of base formula

  if a - int(a) == 0: #a is an int

    return int(a) #Get rid of that decimal :)

  else: #a is a float

    return a #Just return it



#Ye Olde Golden Ratio &lt;www.verbose.net&gt;

phi = 1.6180339887498948

</PRE>And now in the interpreter: <PRE>&gt;&gt;&gt; import moremath

&gt;&gt;&gt; moremath.phi #Floating point numbers aren't that accurate, you may notice

1.6180339887499999

&gt;&gt;&gt; from moremath import logb

&gt;&gt;&gt; logb(2,1024)

10

</PRE>Wow! A module! Just like other modules! But you did it myself! Or I did it 

yourself...or...wait...you did it yourself. If you look in the directory where 

you put moremath.py now, you'll now find a moremath.pyc file. This is a 

'compiled' file, which is not really compiled (it's bytecode - kinda like a Java 

.class file), but has less memory overhead than a .py file. As far as I know 

.pyc files are not portable, though, so if you're just using this module for 

yourself you can use the .pyc but if you want to distribute it, I recommend you 

keep the .py file. In any case, it's certainly easier to edit your source if you 

still have a .py file. Any questions :)? 

<P></P>

<P><FONT size=-2><A 

href="#top">Back 

to top</A></FONT></P>

<HR>



<H2 align=center><A name=close>In Closing</A></H2>

<H3 align=center><A name=perl>Why Python is Better than Perl</A></H3>

<P>I admit it: maybe Python isn't better than Perl. It's different, to say the 

least. For many things it <I>is</I> better. And it's got definite advantages, 

and that's what I thought I'd just review, or look at, or list, or whatever. 

Here goes. </P>

<UL>

  <LI>Intuitiveness. Instead of all that nasty, obfuscated code, Python has 

  syntax and blocking that resembles, somewhat, normal (English) speech and 

  indenting. 

  <LI>High-levelness. List slicing, tuple packing, etc. allow for high-level 

  manipulation of data without all that mucking about with 

  pointers...wait...that's C...and efficient though it may be, it sometimes even 

  confuses the 黚erhacker in me. But it's still easier in Python than Perl. 

  <LI>More integrated object-oriented (OO) support. OO in Perl involves working 

  with hashes as classes and weird stuff like that. Bottom line, Python was 

  designed from the start to be OO...even though I didn't talk about classes too 

  much. Sorry. 

  <LI>Better C integration. Well, this is opinionated here, but I think 

  embedding Python in C is easier than Perl...what can I say? 

  <LI>Interactive mode. No need to put scripts in separate files. You know what 

  I'm saying. 

  <LI>Wider variety of data structures. Perl has arrays, hashes, and scalars. 

  Python has scalars (int, float, long), lists, dictionaries (which I didn't 

  talk about; they're like hashes or associative arrays), tuples. And it's 

  extensible and evolving, according to the docs. 

  <LI>range function. People complain about the lack of a generic for loop, like 

  Perl has. range really makes the for loop...without having a whole different 

  type of loop. Less overhead. And you can use range for other things, too. 

  <LI>Monty Python. 'Nuff said. </LI></UL>

<P><FONT size=-2><A 

href="#top">Back 

to top</A></FONT></P>

<HR>



<H3 align=center><A name=ref>References</A></H3>

<UL>

  <LI><A href="http://www.python.org/">Python.org</A>. A must-see. 

  <LI><A href="http://www.python.org/doc/current/">Current Python docs</A>. 

  Gotta read them. 

  <LI><A href="http://www.zope.org/">Zope</A>. Great webserver written in 

  Python. 

  <LI><A href="http://www.programmershaven.com/zone23/links/link281.htm">Python 

  section at ProgrammersHaven</A>. More good links. 

  <LI><A href="http://blacksun.box.sk/">Black Sun Research Facility</A>. Great 

  site for networking, programming, cracking, OSes, etc. This tutorial should be 

  published there :) 

  <LI><A href="http://www.pythonline.com/">Pythonline</A>. Monty Python, may or 

  may not be the official site, I'm not sure. </LI></UL>

<P>Any comments, questions, glowing praise, rants, hatemail, feel free to <A 

href="mailto:skinite@home.com">mail me</A> or leave a message for me at <A 

href="http://dvd.box.sk/wb/?did=blacksun">BSRF's message board</A>. I'm a 

member, I check it regularly. Hatemail is ok, but death threats are discouraged. 

</P>

<P>Well, we've come to the end, at long last. I hope you've learned something, 

and you aren't too high on the adrenaline rush of coding. I'm not good at these 

ending things, so I think I'll just trail off right...about...now... </P>

<P><FONT size=-2><A 

href="#top">Back 

to top</A></FONT></P></FONT></BODY></HTML>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91啦中文在线观看| 精品国产一区二区三区av性色| 亚洲成人精品一区二区| 日韩免费视频一区二区| 91在线精品一区二区三区| 蜜桃视频一区二区| 一区二区在线观看av| 久久新电视剧免费观看| 欧美日韩成人综合天天影院| 成人福利视频网站| 久久电影网站中文字幕| 亚洲图片欧美综合| 一区精品在线播放| 国产日韩精品久久久| 精品少妇一区二区三区视频免付费 | 精品国内二区三区| 色94色欧美sute亚洲线路二 | 国产成人免费xxxxxxxx| 免费成人美女在线观看| 亚洲高清不卡在线| 一区二区在线看| 中文文精品字幕一区二区| 精品少妇一区二区三区日产乱码 | 91麻豆精品国产91久久久更新时间 | 久久这里只精品最新地址| 欧美三级视频在线观看| 91亚洲精华国产精华精华液| 国产成人av在线影院| 国产在线不卡一卡二卡三卡四卡| 日本系列欧美系列| 亚洲.国产.中文慕字在线| 亚洲一区二区三区四区五区黄 | 亚洲成人高清在线| 樱桃国产成人精品视频| 亚洲图片激情小说| 亚洲人成小说网站色在线| 国产精品初高中害羞小美女文| 国产日韩欧美在线一区| 欧美国产精品专区| 国产精品私人影院| 国产精品国产自产拍在线| 国产精品网站在线| 国产精品视频你懂的| 国产日韩欧美麻豆| 国产精品国产三级国产aⅴ原创| 国产精品视频一二三区| 亚洲视频一区在线观看| 一区二区激情小说| 亚洲自拍偷拍av| 五月激情六月综合| 日本sm残虐另类| 激情综合一区二区三区| 久久国产精品露脸对白| 国产一区二区三区美女| 粉嫩在线一区二区三区视频| jlzzjlzz欧美大全| 色综合久久66| 欧美日韩免费高清一区色橹橹 | 日韩高清在线不卡| 免费观看成人av| 国产老女人精品毛片久久| 懂色av中文一区二区三区| av在线综合网| 欧美日韩精品电影| 精品va天堂亚洲国产| 国产欧美精品一区aⅴ影院 | 免费不卡在线观看| 国产一区二区免费看| 91在线视频免费观看| 欧美天堂一区二区三区| 欧美一区二区女人| 国产色一区二区| 一个色在线综合| 麻豆91小视频| 91一区二区在线观看| 欧美精品久久一区| 亚洲国产成人午夜在线一区| 亚洲一区视频在线观看视频| 久久疯狂做爰流白浆xx| 色噜噜狠狠成人中文综合| 91精品国产欧美一区二区成人| 国产欧美va欧美不卡在线| 亚洲一区二区三区爽爽爽爽爽 | 国产精品成人在线观看| 午夜精品久久久久久久蜜桃app| 精品影院一区二区久久久| 97久久超碰国产精品电影| 欧美一区二区三区免费在线看 | 蜜臀av亚洲一区中文字幕| 国产精品1024| 777xxx欧美| 亚洲日本在线天堂| 精品一区二区三区日韩| 91官网在线观看| 久久综合狠狠综合久久综合88| 亚洲国产一区二区视频| 不卡免费追剧大全电视剧网站| 欧美片网站yy| 中文字幕一区在线| 激情综合色播五月| 欧美色网一区二区| 国产精品国模大尺度视频| 九九精品一区二区| 欧美精品一卡二卡| 亚洲激情网站免费观看| 成人av在线网站| 久久一区二区视频| 石原莉奈在线亚洲二区| 色狠狠色噜噜噜综合网| 国产精品久久毛片| 国产毛片精品视频| 欧美一级日韩免费不卡| 亚洲国产毛片aaaaa无费看 | 欧美体内she精高潮| 国产精品久久久久久久久快鸭| 久久国产三级精品| 欧美日本韩国一区二区三区视频 | 中文字幕一区av| 国产不卡高清在线观看视频| 日韩美女视频在线| 肉肉av福利一精品导航| 欧美日韩一区二区欧美激情| 亚洲免费av高清| 99综合电影在线视频| 亚洲国产精品99久久久久久久久 | 一区二区三区欧美在线观看| 97成人超碰视| 中文字幕日韩欧美一区二区三区| 国产精品888| 国产亚洲1区2区3区| 国产麻豆精品久久一二三| 精品福利视频一区二区三区| 毛片不卡一区二区| 日韩天堂在线观看| 麻豆精品国产91久久久久久| 日韩视频免费观看高清完整版 | 国产一区二区91| 久久久久久久精| 成人激情图片网| 亚洲少妇屁股交4| 色国产综合视频| 亚洲电影一级片| 777欧美精品| 狠狠狠色丁香婷婷综合激情| 久久久久久亚洲综合| 成人一区二区视频| 亚洲欧美另类小说| 欧美日韩在线三区| 日韩和欧美一区二区| 日韩视频永久免费| 国产一区二区女| 亚洲欧洲精品一区二区精品久久久| 99在线精品免费| 亚洲一区二区三区四区的| 欧美一区二区三区日韩| 国产最新精品免费| 亚洲欧洲韩国日本视频| 在线亚洲一区二区| 日韩一区精品字幕| 久久综合给合久久狠狠狠97色69| 成人亚洲一区二区一| 亚洲一区二区三区在线看| 日韩欧美在线一区二区三区| 国产老女人精品毛片久久| 亚洲欧美另类久久久精品| 欧美日韩精品欧美日韩精品一综合| 日本成人在线看| 国产精品进线69影院| 欧美日韩精品免费| 国产成人久久精品77777最新版本| 亚洲图片欧美激情| 日韩欧美你懂的| www..com久久爱| 蜜臀精品一区二区三区在线观看| 国产嫩草影院久久久久| 欧美性大战久久| 国产一区二区三区精品视频| 亚洲精品成人悠悠色影视| 日韩一区二区三区四区| 成年人网站91| 美女一区二区三区| 亚洲精品中文在线| 91精品国产全国免费观看| a级精品国产片在线观看| 人妖欧美一区二区| 亚洲视频狠狠干| 久久久不卡影院| 欧美群妇大交群中文字幕| 波多野结衣中文字幕一区二区三区| 亚洲成人免费视| 中文字幕综合网| 久久久久国产精品厨房| 欧美性色欧美a在线播放| 成人一区二区三区| 蜜桃视频在线观看一区| 一区二区三区不卡在线观看 | 寂寞少妇一区二区三区| 亚洲第一久久影院| 最新国产の精品合集bt伙计| 26uuu欧美|