Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TTC2030
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AB6912
TTC2030
Commits
4606fc07
Commit
4606fc07
authored
3 years ago
by
Sampsa Tervo
Browse files
Options
Downloads
Patches
Plain Diff
uudet
parent
c1ed3a2b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Demot/demo_read.py
+11
-0
11 additions, 0 deletions
Demot/demo_read.py
Demot/demo_write.py
+35
-0
35 additions, 0 deletions
Demot/demo_write.py
testi.txt
+2
-0
2 additions, 0 deletions
testi.txt
with
48 additions
and
0 deletions
Demot/demo_read.py
0 → 100644
+
11
−
0
View file @
4606fc07
#luetaan olemassa oleva tekstitiedosto
try
:
f
=
open
(
"
c:/users/AB6912/autot.txt
"
,
"
r
"
)
lines
=
f
.
readlines
()
f
.
close
()
print
(
lines
)
for
x
in
lines
:
print
(
"
Tallissa on
"
,
x
)
print
(
"
Homma hoidettu!
"
)
except
:
print
(
"
Ei onnistunut
"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Demot/demo_write.py
0 → 100644
+
35
−
0
View file @
4606fc07
#Demo tiedostojen käsittelystä
try
:
#kirjoitetaan tekstitiedostoon
#avataan tiedosto, kerrotaan avataanko se lukemista vai kirjoittamista varten
#absoluuttinen hakemistopolku
filename
=
"
c:
\\
users
\\
AB6912
\\
testi.txt
"
#käytetään valmista kirjastoa ja ohjataan tiedosto kirjautuneen käyttäjän kotihakemistoon
import
os
filename
=
os
.
path
.
expanduser
(
'
~/
'
)
+
'
test.txt
'
file
=
open
(
filename
,
"
w
"
)
#kirjoitetaan tiedostoon write-metodilla
#\n tekee uuden rivin
file
.
write
(
"
Creating a file with Python!
"
)
file
.
write
(
"
\n
"
)
file
.
write
(
"
Today is 1.1.2021
"
)
#jos halutaan kirjoittaa lista tiedostoon
lista
=
[
"
aaa
"
,
"
bbb
"
,
"
ccc
"
]
for
x
in
lista
:
file
.
write
(
"
\n
"
+
x
)
#toinen vaihtoehto listan kirjoittamiseen
lista2
=
[
"
111
"
,
"
222
"
,
"
333
"
,
"
444
"
]
file
.
writelines
(
lista2
)
#huom! listassa voi olla vain merkkijonoja
#tulosteen voi ohjata myös tiedostoon, ei siis tule näytölle
print
(
"
\n
This is the last line
"
,
file
=
file
)
#suljetaan tiedosto
file
.
close
()
print
(
"
Tehtävä onnistui!
"
)
except
:
print
(
"
Ei onnistunut!
"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
testi.txt
0 → 100644
+
2
−
0
View file @
4606fc07
Creating a file with Python!
Today is 1.1.2021
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment