Code Monkey home page Code Monkey logo

lc-python-intro's Introduction

Library Carpentry: Python Intro for Libraries

Maintainers for Library Carpentry: Python Intro for Libraries

The updated version of this lesson (June 2024) was developed with the assistance of David Palmquist and Scott Peterson.

Lesson Maintainers communication is via the team site.

Past Maintainers for Library Carpentry: Python Intro for Libraries

Library Carpentry

Library Carpentry is a software and data skills training programme for people working in library- and information-related roles. It builds on the work of Software Carpentry and Data Carpentry. Library Carpentry is an official Lesson Program of The Carpentries.

License

All Software, Data, and Library Carpentry instructional material is made available under the Creative Commons Attribution license.

Contributing

There are many ways to discuss and contribute to Library Carpentry lessons. The easiest way to get started is to file an issue to tell us about a spelling mistake, some awkward wording, or a factual error. This is a good way to introduce yourself and to meet some of our community members. See Contributing for more information about contributing Pull Requests and connecting with others in the Carpentries.

Code of Conduct

All participants should agree to abide by The Carpentries Code of Conduct.

Authors

Library Carpentry is authored and maintained through issues, commits, and pull requests from the community.

Citation

(Add citation once Zenodo is updated)

lc-python-intro's People

Contributors

aaren avatar abostroem avatar bennet-umich avatar biologyguy avatar c-martinez avatar chennesy avatar danmichaelo avatar dheles avatar elliewix avatar geyslein avatar iimog avatar jt14den avatar justbennet avatar katrinleinweber avatar konrad avatar lo5an avatar lwrubel avatar mcritchlow avatar montoyjh avatar nikhilweee avatar ntmoore avatar quist00 avatar richyvk avatar scottcpeterson avatar shyamd avatar tobyhodges avatar upendrak avatar valentina-s avatar wking avatar zkamvar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lc-python-intro's Issues

Review with Carpentries Style Guide

How could the content be improved?

Following a major lesson redesign on June 17, 2024, it would be helpful if contributors reviewed specific episodes for style issues using the Carpentries style guide. The authors and maintainers of the updated lesson followed the guide, in general, but haven't reviewed each episode closely for style or consistency.

Contributors hoping to help out can comment on this issue with suggested changes. More experienced community members are welcome to submit PRs for specific episodes (one at a time) and assign @chennesy as a Reviewer. I will track progress here and check off episodes once they have been reviewed for style:

  • Summary and Setup
  • Getting Started
  • Variables and Types
  • Lists
  • Built-in Functions and Help
  • Libraries & Pandas
  • For Loops
  • Looping Over Data Sets
  • Using Pandas
  • Conditionals
  • Writing Functions
  • Tidy Data with Pandas
  • Data Visualisation
  • Wrap-Up

Note on python debugging

When I teach python debugging, I usually tell people to start by reading the bottom of the error, which usually tells you what is wrong, and then look to the beginning to find out where it is wrong. A python error message just read start to finish can be fairly intimidating to a novice. Feel free to dismiss this suggestion!

Redesigned lesson to be merged June 14, 2024

How could the content be improved?

@LibraryCarpentry/curriculum-advisors recently approved a redesigned version of this lesson for adoption into the LC curriculum. The new version of the lesson will be merged into this repository on 14 June 2024.

Notes for myself on what needs doing and when:

  • add notices to repositories and sites of current and new lesson versions notifying visitors of the scheduled change
  • open a pull request to make the change, to be merged on 2024-06-14 - Edit: done
  • [on 2024-06-14] release current version of lesson repository to Zenodo - Edit: original lesson isn't on Zenodo
  • [on 2024-06-14] merge pull request, replacing current version with redesigned lesson Edit: done 06-17
  • [on 2024-06-14] release new version of lesson repository to Zenodo
  • [on 2024-06-14] close other outstanding issues and pull requests on this repository that have been invalidated by the change Edit: done 06-14
  • [on 2024-06-14] transfer existing issues from https://github.com/chennesy/lc-python-intro/issues to this repository Edit: done 06-17
  • [on 2024-06-14] archive https://github.com/chennesy/lc-python-intro repository and redirect visitors to this repo Edit: done 06-17

Format Challenges and Solutions in For Loops in Episode 12 - Possible solution for Identifying Variable Name Errors

Solution:

The first error is "NameError: name 'Number' is not defined". This variable error is a misspelled variable. The variable was defined with a lower case (number) but used later with a different spelling (Number).

The second error is "NameError: name 'message' is not defined". This variable error is a variable that should have been defined but was not. The script uses the variable message to build a message by appending strings to the original message. The variable must first be defined with an original message, in this case, it is an empty string.

The third error is "NameError: name 'a' is not defined". The variable error is a string with no quotes. The "a" is currently used as a variable in the script. However, the goal of the script is to add the letter 'a' as a string. Adding quotes around the "a" will solve the variable error.

The solution without any variable name errors is:

message = ""

for number in range(10):
# use a if the number is a multiple of 3, otherwise use b
if (number % 3) == 0:
message = message + "a"
else:
message = message + "b"
print(message)

Document how to use Jekyll for local development

Unless I'm missing something, there is a Makefile that allows someone doing local development to run a jekyll server to validate their changes, but there doesn't seem to be any documentation on how to actually leverage this. I was thinking of adding this either to the main README or to the CONTRIBUTING file. Preference?

cc/ @jt14den

Consolidating sections on error messaging and troubleshooting

Please delete the text below before submitting your contribution.


A quick note that when going through this lesson, I found it a bit jarring to have a section on determining where errors pop up under the "Variable Scope" episode. Would it make more sense to include this within the explanation of various errors that can occur in "Built-in Functions and Help"? It seems disconnected from the larger flow.

Contribution: Naming Conventions in Episode 02: Variables and Assignment

Hey,

I noticed that one crucial point is missing on the naming conventions of variables, it says:
"Variable names:

  • cannot start with a digit
  • cannot contain spaces, quotation marks, or other punctuation
  • may contain an underscore (typically used to separate words in long variable names)"

You should add a fourth point:

  • are case-sensitive (so "first_name", "First_Name", "first_Name" are all different variables!)

Also I would reformulate the first point in what's allowed for variable names and not saying what's not allowed: You are saying they cannot start with a digit, but that implies they can start with anything else so also with special characters like "?age". It's better to say:

Variable names

  • must start with a capital or non-capital letter or an underscore, you cannot start a variable name with any other special character or a number.

Greetings,
Andre

Replace spyder with jupyter notebook in lesson material

Design notes talk about using Jupyter Notebooks, but lesson has an intro to Spyder at the moment.

To stay in synch with other carpentry lessons, use jupyter notebook:

  1. add some basic info on jupyter notebook to setup.md and delete info on spyder
  2. exchange spyder related info in other lesson with necessary info on jupyter notebook (check design notes and other carpentry lessons - Data Carpentry Ecology, Software Carpentry)

Checkout Suggestion on Python Intro for Libraries Lesson: For Loops page

In the Python Intro for Libraries Lesson: For Loops episode, it might be clearer to new learners if the first 2 blocks of code were reordered. When I've taught this lesson as a demo, I've done it this way and it seems to go very well. After the introduction on what a For loop does, show the steps the "long way" first, then demo the more elegant way of using a loop to accomplish the same task:

  1. print(2)
    print(3)
    print(5)
  2. This series of print statements is equivalent to a for loop:
    for number in [2, 3, 5]:
    print(number)
  3. And the output for both is the same:
    2
    3
    5

Improve / move the episode "Programming Style"

In our maintainer call 2019-03-20 we agreed that PEP008 and coding style should be addressed but that the current version of the episode needs be improved (but this has low priority). For the time being the episode should be kept and stay at the end of the lesson. In future the topic coding style and PEP008 could be covered earlier e.g. when explaining the different IDE for writing Python code.
The current part about the assert statement should be removed as it is too advanced.

Links need to be fixed in CONTRIBUTING.md

The Contributing Guide, CONTRIBUTING.md, contains two links with URLs that should be updated:

  1. the How to Contribute to an Open Source Project on GitHub link leads to a 404 and should be updated to link to https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github
  2. the [repo] link reference currently points to a placeholder URL (https://example.com/FIXME) and should be updated to point to the source repository for the lesson (i.e. this GitHub repository).

The Contributing Guide is one of the files that is unique to each repository - to allow for individual lesson projects to define their own guidance for contributors - so unfortunately this is not an issue that can be fixed centrally e.g. by updating the template files in the lesson infrastructure. Instead the file must be updated in the individual lesson repositories themselves.

Fix the FIXMEs

A search for FIXME currently finds both visible & invisible occurrences (not including those in the lesson-check function, etc).
https://github.com/LibraryCarpentry/lc-python-intro/search?p=2&q=FIXME&unscoped_q=FIXME

I think these should be replaced with content, with priority on those that appear in the lesson itself:

https://github.com/LibraryCarpentry/lc-python-intro/blob/gh-pages/_episodes/10-lunch.md
https://github.com/LibraryCarpentry/lc-python-intro/blob/gh-pages/_episodes/16-coffee.md

Followed by those in the extras (presuming we have meaningful content):
https://github.com/LibraryCarpentry/lc-python-intro/blob/gh-pages/_extras/discuss.md
https://github.com/LibraryCarpentry/lc-python-intro/blob/gh-pages/_extras/exercises.md

add instructor notes (tidy data)

How could the content be improved?

Outline option for instructors to teach the tidy-data episode only as a conceptual lesson and skip the live coding using df.melt() and the datetime conversion, since these can be difficult concepts to grasp for beginners. Instructors can skip to the data-viz episode in that case and import the df_long.pkl from the data.zip download at the beginning of the episode to work with the updated dataset.

Note: transferred manually from chennesy repo fork since Issue transfer wasn't available to this repo.

Which part of the content does your suggestion apply to?

https://librarycarpentry.org/lc-python-intro/instructor/tidy.html

Consider adding back extend()

With the merge of PR #47, list.extend() is no longer included in the discussion of lists. Consider adding that back in to future content.

Python Intro for Libraries: For Loops - Coding Error under Practice Accumulating

In line 290, under Practice Accumulating, I believe there is a coding error in the second example, shown here:

List of word lengths: ["red", "green", "blue"] => [3, 5, 4]
lengths = ____
for word in ["red", "green", "blue"]:
lengths.____( ____ )
print(lengths)

The second last line contains a typo--a period instead of an equals sign:

Instead of: lengths.____( ____ )
I propose this: lengths = ____( ____ )

This correction ensures the code fetches the desired result:

Program

lengths = 0
for word in ["red", "green", "blue"]:
lengths = len(word)
print(lengths)

Result When Run

3
5
4

Reference URL

RE: https://librarycarpentry.org/lc-python-intro/12-for-loops/index.html

TypeError at "Spot the difference"

Is the "Spot the difference" example (source) working for you in Spyper? I get this error in Spyder 3.2.8 with Python 3.6.4 64bits, Qt 5.6.2 & PyQt5 5.6 on Windows.

Traceback (most recent call last):

  File "<ipython-input-...>", line ..., in <module>
    print(max(rich, poor))

TypeError: 'str' object is not callable

Works fine in Jupyter 5.5.0, so this can be closed if #27 is implemeted ;-)

June 2019 Lesson Release checklist

If your Maintainer team has decided not to participate in the June 2019 lesson release, please close this issue.

To have this lesson included in the 18 June 2019 release, please confirm that the following items are true:

  • Example code chunks run as expected
  • Challenges / exercises run as expected
  • Challenge / exercise solutions are correct
  • Call out boxes (exercises, discussions, tips, etc) render correctly
  • A schedule appears on the lesson homepage (e.g. not “00:00”)
  • Each episode includes learning objectives
  • Each episode includes questions
  • Each episode includes key points
  • Setup instructions are up-to-date, correct, clear, and complete
  • File structure is clean (e.g. delete deprecated files, insure filenames are consistent)
  • Some Instructor notes are provided
  • Lesson links work as expected

When all checkboxes above are completed, this lesson will be added to the 18 June lesson release. Please leave a comment on carpentries/lesson-infrastructure#26 or contact Erin Becker with questions ([email protected]).

Possible major updates (LC-CAC)

Hi @konrad @dheles @elliewix @lwrubel @c-martinez @richyvk,

LC-CAC (@LibraryCarpentry/curriculum-advisors) recently discussed revamping this Python lesson and making some significant changes. We discussed moving to Jupyter, for example, and replacing the gapminder data with a more library-specific dataset, like the DOAJ data from the OpenRefine lesson. The Carpentries recently reached out to all maintainers and given the response, this lesson officially doesn't have any current active maintainers (cc @tobyhodges). But before moving forward, I wanted to double check with everyone listed in the repo's readme to see if you wanted to continue to work on this lesson.

If you do want to keep working on this, that would be great! We should chat more about possibilities to get the lesson moving towards beta again. Also: no problem if you don't want to work on this any longer. I'm happy to take this one over with some new maintainers and get it on a road towards beta.

thanks,
Cody

Conditionals are used before they are introduced in lesson 13.

"If statements" are used for the first time in lesson 9 (For Loops) in "Identifying Variable Name Errors" and also multiple time in lesson 10 "Writing Functions". So lesson 13 "Conditionals" where "if statements" are officially introduced comes too late.

Transition To Workbench in May

@librarycarpentry/lc-python-intro-maintainers

As I hope you are already aware, we are rolling out the new lesson infrastructure, The Carpentries Workbench, across all of The Carpentries official lessons in early May 2023. This means that all Data Carpentry, Library Carpentry, and Software Carpentry lesson repositories will be modified to adopt the new infrastructure in the coming days.

You can follow the transition of this lesson repository at carpentries/lesson-transition#66.

The transition has already taken place for several lessons, and so far the process has been running quite smoothly. You should see the transition take place with minimal disruption, but there are a few things that it is important for Maintainers to be aware of.

Here is what you can expect to happen next:

  1. Any open pull requests on the repository will be closed with an automated message.
  2. The repository will be set to read-only mode for a brief period while the transition occurs.
  3. The new repository structure and lesson site layout will then be applied.
  4. To avoid anyone accidentally pushing the old commit history back to the repository, after the transition Maintainers will need to delete and replace any existing forks and local clones they have of the lesson repository, and confirm that they have done so by replying to this issue.

I will reply here before and after the transition has taken place. If you have any questions in the meantime, please reach out to the Curriculum Team by tagging us here, e.g. @librarycarpentry/core-team-curriculum.

If you would like to read more about the new lesson infrastructure and the modified repository structure you can expect post-transition, I recommend the Infrastructure episode of the Maintainer Onboarding curriculum and the Workbench Transition Guide, which includes a side-by-side comparison of various elements of the old and new infrastructures.

For Loops in Episode 12 Exercise "Cumulative Sum" is Impossible

Here's the task:
Reorder and properly indent the lines of code below so that they print an array with the cumulative sum of data. The result should be [1, 3, 5, 10].
The aforementioned code:

cumulative += [sum]
for number in data:
cumulative = []
sum += number
print(cumulative)
data = [1,2,2,5]

Now, the problem here is that sum is never initialized. I believe the intended solution to be

data = [1, 2, 2, 5]
cumulative = []
sum = 0
for number in data:
    sum += number
    cumulative += [sum]
print(cumulative)

but, that's impossible to do with just the directions of reordering and indenting lines (I had to add the sum = 0 line).

Need more elaboration for Encapsulation Data Analysis section on #10 Writing Functions

Encapsulating Data Analysis exercise on Lesson 10 could use some extra elaboration as to what it's trying to achieve. This is the first instance where pandas is in use in this course. For example, it might be worthwhile to explain what df.ix and japan.ix do. Also it might be good to explain what pandas.read_csv do. Took us a while to understand why would a formula to calculate average GDP would only take into account two years. What's unsaid is that the data in the csv only include those two years (1982 and 1987)

The requirement to assume the code has been executed presents a leap in learning difficulty. More scaffolding could be helpful.

(Thank you for this course. We've been doing one lesson per week and it's far less intimidating and more relevant than other resources we've encounted. Thank you. )

Lesson: https://librarycarpentry.org/lc-python-intro/14-writing-functions/index.html

The last solution in "18-style.md" throw an error as the variable "s" is not defined.

Please delete the text below before submitting your contribution.


def string_machine(input_string, iterations):
"""
Takes input_string and generates a new string with -'s and *'s
corresponding to characters that have identical adjacent characters
or not, respectively. Iterates through this procedure with the resultant
strings for the supplied number of iterations.
"""

"Assigned the input_string to variable s so that it can be used later in the for loop, otherwise the code throw an error"
s = input_string

print(input_string)
old = input_string
for i in range(iterations):
    new = ''
    # iterate through characters in previous string
    for j in range(len(s)):
        left = j-1
        right = (j+1)%len(s) # ensure right index wraps around
        if old[left]==old[right]:
            new += '-'
        else:
            new += '*'
    print(new)
    # store new string as old
    old = new

string_machine('et cetera', 10)


Suggestion on Conditionals Episode

With the Conditionals episode, examples are given using the variable mass or m inconsistently throughout the page. Although the code executes without errors, it would be kinder to a beginning learner to keep things consistent. Perhaps spell out the variable in the first exercise, then use it as a teaching opportunity to show how it can be safely abbreviated, for ease of writing/re-writing the code:

First example:

mass = 3.54
if mass > 3.0:
    print(mass, 'is larger')

Then:

masses = [3.54, 2.07, 9.22, 1.86, 1.71]
for m in masses:
    if m > 3.0:
        print(m, 'is larger')

I'm afraid the example in the elif section has a mix of both, which prompted me to make this suggestion:

masses = [3.54, 2.07, 9.22, 1.86, 1.71]
for mass in masses:
    if m > 9.0:
        print(m, 'is HUGE')
    elif m > 3.0:
        print(mass, 'is larger')
    else:
        print(mass, 'is smaller')

Lesson Contribution: Feedback

I'm a member of The Carpentries Core Team and I'm submitting this issue on behalf of another member of the community. In most cases, I won't be able to follow up or provide more details other than what I'm providing below.


I already went through the total course and made some notes about things which are not totally clear for me. Maybe this helps also to improve the course a little bit. So here are my remarks, questions, ideas and suggestions:

In section "Libraries"

  • In the exercise "Exploring the os Library" if the library is imported you can type help(os), but you cannot reach the top of the information. How can this be done?
  • it is not clear for me why in the exercise "Locating the Right Module" in the Solution "datetime.date(year, month, day).isoformat()" is used, because it works also without "isoformat()"

In section "For Loops"

  • in "The Accumulator pattern turns many values into one." it is maybe an idea to show also the "+=" operator, because it is used in the later exercise "Cumulative Sum"
  • for the exercises "Tracing Execution", "Practice Accumulating", "Identifying Variable Name Errors" the Solution is missing

In section "Writing Functions"

  • the solution for exercise "Encapsulation" does not work for me. If I use min(data) I get the minimum, but it is a string.
  • in exercise "Find the First" the last question is not answered in the Solution
  • in exercise "Encapsulate of If/Print Block" some parts of the Solution is missing and in IMHO the solution given for the last part is not taking into account, that there also can be "small" eggs (between 55 and 50 grams).
  • I cannot understand the exercise "Encapsulating Data Analysis"

In section "Programming Style"

  • After the first example ("Use assertions to check for internal errors.") it is stated "…The source code for the expression that failed will be displayed as part of the error message. …". But this is not true if I use the function with volume = 0. Only the message "AssertionError" is displayed.
  • In the example for "Use docstrings to provide online help" it seems that there is a mistake in the last line of the function "average". In the example it is "return sum(values) / average(values)" and I think it should be "return sum(values) / len(values)".
  • For the first exercise "What Will Be Shown?" the solution is not fully clear for me. IMHO the first string in the function '''Determine overall maximum edit distance.''' will show up in online help but not the second line '''Avoid checking sequence against itself.''' because it is not at the beginning of the function. I tested the source code and the second line did not show up in online help.
  • Exercise "Clean Up This Code": It is not clear for me how to run this program; and for the solution it seems for me that the variable s should be replaced with input_string.

Handout?

This is a migrated issue.

This lesson might benefit from making a handout of reference materials.

To do this, add detail of commands/terminology under the keypoints headers for each lesson. This effectively then builds a handout at - for example http://librarycarpentry.github.io/lc-data-intro/reference/ - which can be printed out in advance of the session (librarians love handouts!)

Make sure you make a note of this in your Instructor Notes.

Updating Lessons 1-3

I would suggest a few changes to lessons 1-3 in Python.

First, I think there needs to be alternate lesson 1's. One for spyder and one for jupyter. All the python sessions I have attended have used jupyter.

Second I would add some of the command line math into lesson 2, that is currently in lesson 1.

Many librarians are going to be complete newbies and it will be important for them to understand data types before they really start using variables. I would take the top section on variable types and using the type function in lesson 3 and insert it into lesson 2 before "variables can be used in calculations."

Third in lesson 2 I would I would move up the case sensitive and meaningful variable names higher up near the beginning of lesson 2.

Finally I would remove index and slicing from lesson two and put them at the end of lesson 3.


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.