Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
67e9fb9d
Kaydet (Commit)
67e9fb9d
authored
Şub 19, 2006
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #1215184: fileinput now has a fileno() function for getting the
current file number.
üst
602b9ba6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
7 deletions
+51
-7
libfileinput.tex
Doc/lib/libfileinput.tex
+11
-4
fileinput.py
Lib/fileinput.py
+21
-3
test_fileinput.py
Lib/test/test_fileinput.py
+16
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/lib/libfileinput.tex
Dosyayı görüntüle @
67e9fb9d
...
...
@@ -62,6 +62,12 @@ The following functions use the global state created by
line has been read, returns
\code
{
None
}
.
\end{funcdesc}
\begin{funcdesc}
{
fileno
}{}
Return the integer ``file descriptor'' for the current file. When no
file is opened (before the first line and between files), returns
\code
{
-1
}
.
\end{funcdesc}
\begin{funcdesc}
{
lineno
}{}
Return the cumulative line number of the line that has just been
read. Before the first line has been read, returns
\code
{
0
}
. After
...
...
@@ -107,10 +113,11 @@ module is available for subclassing as well:
\begin{classdesc}
{
FileInput
}{
\optional
{
files
\optional
{
,
inplace
\optional
{
, backup
}}}}
Class
\class
{
FileInput
}
is the implementation; its methods
\method
{
filename()
}
,
\method
{
lineno()
}
,
\method
{
fileline()
}
,
\method
{
isfirstline()
}
,
\method
{
isstdin()
}
,
\method
{
nextfile()
}
and
\method
{
close()
}
correspond to the functions of the same name in the
module. In addition it has a
\method
{
readline()
}
method which
\method
{
filename()
}
,
\method
{
fileno()
}
,
\method
{
lineno()
}
,
\method
{
fileline()
}
,
\method
{
isfirstline()
}
,
\method
{
isstdin()
}
,
\method
{
nextfile()
}
and
\method
{
close()
}
correspond to the functions
of the same name in the module.
In addition it has a
\method
{
readline()
}
method which
returns the next input line, and a
\method
{__
getitem
__
()
}
method
which implements the sequence behavior. The sequence must be
accessed in strictly sequential order; random access and
...
...
Lib/fileinput.py
Dosyayı görüntüle @
67e9fb9d
...
...
@@ -73,7 +73,6 @@ XXX Possible additions:
- optional getopt argument processing
- specify open mode ('r' or 'rb')
- fileno()
- isatty()
- read(), read(size), even readlines()
...
...
@@ -153,6 +152,15 @@ def filelineno():
raise
RuntimeError
,
"no active input()"
return
_state
.
filelineno
()
def
fileno
():
"""
Return the file number of the current file. When no file is currently
opened, returns -1.
"""
if
not
_state
:
raise
RuntimeError
,
"no active input()"
return
_state
.
fileno
()
def
isfirstline
():
"""
Returns true the line just read is the first line of its file,
...
...
@@ -175,8 +183,9 @@ class FileInput:
"""class FileInput([files[, inplace[, backup]]])
Class FileInput is the implementation of the module; its methods
filename(), lineno(), fileline(), isfirstline(), isstdin(), nextfile()
and close() correspond to the functions of the same name in the module.
filename(), lineno(), fileline(), isfirstline(), isstdin(), fileno(),
nextfile() and close() correspond to the functions of the same name
in the module.
In addition it has a readline() method which returns the next
input line, and a __getitem__() method which implements the
sequence behavior. The sequence must be accessed in strictly
...
...
@@ -334,6 +343,15 @@ class FileInput:
def
filelineno
(
self
):
return
self
.
_filelineno
def
fileno
(
self
):
if
self
.
_file
:
try
:
return
self
.
_file
.
fileno
()
except
ValueError
:
return
-
1
else
:
return
-
1
def
isfirstline
(
self
):
return
self
.
_filelineno
==
1
...
...
Lib/test/test_fileinput.py
Dosyayı görüntüle @
67e9fb9d
...
...
@@ -167,3 +167,19 @@ try:
verify
(
lines
==
[
"A
\n
"
,
"B"
])
finally
:
remove_tempfiles
(
t1
)
if
verbose
:
print
"16. fileno()"
try
:
t1
=
writeTmp
(
1
,
[
"A
\n
B"
])
t2
=
writeTmp
(
2
,
[
"C
\n
D"
])
fi
=
FileInput
(
files
=
(
t1
,
t2
))
verify
(
fi
.
fileno
()
==
-
1
)
line
=
fi
.
next
()
verify
(
fi
.
fileno
()
!=
-
1
)
fi
.
nextfile
()
verify
(
fi
.
fileno
()
==
-
1
)
line
=
list
(
fi
)
verify
(
fi
.
fileno
()
==
-
1
)
finally
:
remove_tempfiles
(
t1
,
t2
)
Misc/NEWS
Dosyayı görüntüle @
67e9fb9d
...
...
@@ -366,6 +366,9 @@ Extension Modules
Library
-------
- Patch #1215184: fileinput now has a fileno() function for getting the
current file number.
- Patch #1349274: gettext.install() now optionally installs additional
translation functions other than _() in the builtin namespace.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment