Tying Up Loose Ends - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Tying Up Loose Ends

Description:

File names without paths default to the current working directory that the ... Cheating with Maps. We can use tuples and maps to 'cheat' Creating. X ={} Reading ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 12
Provided by: Ada581
Category:
Tags: cheat | ends | loose | tying

less

Transcript and Presenter's Notes

Title: Tying Up Loose Ends


1
Tying Up Loose Ends
2
Topics
  • Interpreter working directory (files)
  • Complex Data structures
  • Specialized Data structures

3
Working Directory
  • Sometimes we dont want to write in a complete
    path for our files
  • So what does this do?
  • fopen("test.txt)
  • How can we get it to do what we want?

4
Current Working Directory
  • File names without paths default to the current
    working directory that the python interpreter was
    started in
  • So the trick is to start the interpreter in the
    directory that we want to be current.

5
CWD Advantages
  • CWD is already in sys.path
  • You can import modules easily
  • Files dont require the full path

6
Complex Data Structures
  • 2D lists
  • 3D lists
  • Sparse structures with maps

7
2D Lists
  • Why?
  • Game boards
  • Lookup tables
  • How
  • X 0 for i in xrange(10) for j in
    xrange(10)
  • Are there any other ways?

8
Using 2D lists
  • X34 1
  • How about pretty printing it?
  • for i in X
  • for x in i
  • print x,
  • print

9
3D Lists
  • These are like 2D only one more dimension
  • We may use these for 3D board games, but they are
    less common than 2D structures
  • How do we make them?
  • ?
  • How do we use them?
  • ?

10
Cheating with Maps
  • We can use tuples and maps to cheat
  • Creating
  • X
  • Reading
  • X.setdefault((3,4),0)
  • Writing
  • X(3,4) 3

11
Challenge
  • Build a 2D Tic Tac Toe game
  • Build a 3D Tic Tac Toe game
Write a Comment
User Comments (0)
About PowerShow.com