Code Monkey home page Code Monkey logo

eca201-week1's Introduction

Week 1 - Lecture

MAC - install specific steps

  1. install tkinter - ActiveTcl 8.5.18.0
  • System Preferences -> Security & Privacy -> General tab -> unlock icon -> You can one time allow TKinter or allow software from anywhere
  1. install pip system wide
    • python get-pip.py

WINDOWS - install specific steps

  1. Windows MSI Installer (2.7.10) - Python 2.7
    • Need to check the install for all users box.
    • Use 64 bit if you have it.
    • If you use the 32 bit follow the instructions for getting pip on MAC.
  2. Set the environment variable
    1. win key -> <search 'thispc'> right click -> properties -> advanced system settings -> Environment Variables
    2. Create a new user variable 'PYTHON27_HOME' value: C:\Python27
    3. Create a new user variable 'PATH' value: %PYTHON27_HOME%;%PYTHON27_HOME%\Scripts
    4. win key -> cmd -> python -V
  3. Set the tkinter env variables in Fixes section at the bottom (If idle fails to start)

GENERAL


  1. install virtualenv system wide

    pip install virtualenv
    
  2. create a new directory for your py201 files

  3. create a virtualenv 'venv' in class directory

    virtualenv venv
    
  4. source venv

  • MAC

    source venv/bin/activate
    
  • WINDOWS

    venv\Scripts\activate
    
  1. pip install openpyxl

    pip install openpyxl
    
  2. create start_idle.py

    • Code Snippet
    from idlelib.PyShell import main
    if __name__ == '__main__':
      main()
    
    • WINDOWS

      notepad start_idle.py
      
      • paste code snippet
      • save and close
    • MAC

      cat > start_idl.py
      <paste code snippet here>
      ^c
      
  3. python start_idle.py

  4. Copy the example code from openpyxl

  5. In idle, File -> new file 'example.py'

  6. Paste the example code

  7. File -> Save

  8. In the idle shell

    import example
    
  9. Quit idle. Close the example.py file

  10. Open the 'sample.xlsx' file You should see data in the default worksheet generated by the example

Homework

  1. Create a new working directory.
  2. Create a new virtualenv. Don't forget to source the env!
  3. Pip install openpyxl.
  4. Download the 'Population by Country' as a local csv.
  5. Create a python file containing the csv to xlsx converter in this stackoverflow.
  6. Modify the code to convert the 'Population by Country'.
    • replace the line f = open(r'C:\Users\Asus\Desktop\herp.csv')

    • with f = open(r'C:\Users\Asus\Desktop\herp.csv', 'rU')

    • because of new-line character seen in unquoted field.

      (mschober)-(jobs:0)-(~/Documents/git/classes/eca201/eca201/week1/homework)
      (! 1136)-> python csv_to_xlsx.py populationbycountry19802010millions.csv populationbycountry19802010millions.xlsx
      The source file is populationbycountry19802010millions.csv
      The target file is populationbycountry19802010millions.xlsx
      Begin converting to xlsx...
      Traceback (most recent call last):
        File "csv_to_xlsx.py", line 27, in <module>
          for row_index, row in enumerate(reader):
      _csv.Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
      
  7. Convert the csv to xlsx and email to [email protected].
    • subject: [eca201] - week1 homework

Example Run

(env)
(mschober)-(jobs:0)-(~/Documents/git/classes/eca201/eca201/week1/homework)
(! 1137)-> vim csv_to_xlsx.py
(env)
(mschober)-(jobs:0)-(~/Documents/git/classes/eca201/eca201/week1/homework)
(! 1138)-> python csv_to_xlsx.py populationbycountry19802010millions.csv populationbycountry19802010millions.xlsx
The source file is populationbycountry19802010millions.csv
The target file is populationbycountry19802010millions.xlsx
Begin converting to xlsx...
Saving the converted file...
Success!

Fixes

  • Fix tkinter windows

    set "TCL_LIBRARY=C:\Python27\tcl\tcl8.5"
    set "TK_LIBRARY=C:\Python27\tcl\tk8.5"
    
    • set these as environment variables

Supplemental

eca201-week1's People

Contributors

mschober avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.