From info at physalia-courses.org Sat Feb 1 06:56:43 2025 From: info at physalia-courses.org (info at physalia-courses.org) Date: Sat, 1 Feb 2025 12:56:43 +0100 (CET) Subject: [Tutor] online course - INTRODUCTION TO PYTHON PROGRAMMING FOR BIOLOGISTS - 24-27 February Message-ID: <1738411003.46932791@webmail.jimdo.com> Dear all, there are the last seats available for our online course - INTRODUCTION TO PYTHON PROGRAMMING FOR BIOLOGISTS Dates: 24?27 February Course Website: [ https://www.physalia-courses.org/courses-workshops/python24/ ]( https://www.physalia-courses.org/courses-workshops/python24/ ) This four-day course is tailored for biologists and life scientists at all levels with little or no prior programming experience. Participants will gain a strong foundation in Python programming and its applications in biological data analysis, with a focus on hands-on exercises and real-world projects. By the end of the course, you will be able to: Write and run Python code for biological data analysis and visualization. Use bioinformatics libraries like BioPython. Perform statistical analysis with Python. Create organized and reusable code. Develop a simple project tailored to your research field. Program Highlights: Day 1: Python basics, data types, and DNA sequence manipulation. Day 2: Dictionaries, loops, and field data analysis. Day 3: I/O handling, BioPython, and ChIP-seq data processing. Day 4: Statistics, visualization, and advanced projects in viral genomics. Best regards, Carlo -------------------- Carlo Pecoraro, Ph.D Physalia-courses DIRECTOR info at physalia-courses.org mobile: +49 17645230846 From akleider at pm.me Sun Feb 2 20:35:44 2025 From: akleider at pm.me (Alex Kleider) Date: Mon, 03 Feb 2025 01:35:44 +0000 Subject: [Tutor] importing modules from a src directory to test in a module in a testing directory Message-ID: <8Y_fxPhGwwmJmqzZLivNJYFQ0pPtZIWEyc8KC2GEVT0yiHSM47iTCe2RDlz8JifP1EAFDZiXg-kVrZjffgSfLFCKU7BZqXOQj8oDZcz8odg=@pm.me> How to import a module from a src directory for testing in a test program found in a sister test directory? Using Debian Linux... Here's my project's directory structure: TopLevel ??? __init__.py ??? src ??? ??? __init__.py ??? ??? myprogram.py ??? tests ??? __init__.py ??? test_myprogram.py ... and content of relevant files: $ cat src/myprogram.py #!/usr/bin/env python3 # File: utils/myprogram.py def print_greeting(): greeting = "Helo world" print(greeting) return greeting if __name__ == "__main__": print_greeting() $ cat tests/test_myprogram.py #!/usr/bin/env python3 # File: tests/test_myprogram.py from .. src import myprogram ... then attempting to run the test: $ ./tests/test_myprogram.py Traceback (most recent call last): File "/home/alex/Projects/TopLevel/./tests/test_myprogram.py", line 5, in <module> from ..src import myprogram ImportError: attempted relative import with no known parent package Any help as to how this can be fixed would be most welcome! Cheers, Alex Kleider Alex Kleider (he/him) ...sent from my current gismo! From leamhall at gmail.com Wed Feb 5 09:12:05 2025 From: leamhall at gmail.com (Leam Hall) Date: Wed, 5 Feb 2025 08:12:05 -0600 Subject: [Tutor] importing modules from a src directory to test in a module in a testing directory In-Reply-To: <8Y_fxPhGwwmJmqzZLivNJYFQ0pPtZIWEyc8KC2GEVT0yiHSM47iTCe2RDlz8JifP1EAFDZiXg-kVrZjffgSfLFCKU7BZqXOQj8oDZcz8odg=@pm.me> References: <8Y_fxPhGwwmJmqzZLivNJYFQ0pPtZIWEyc8KC2GEVT0yiHSM47iTCe2RDlz8JifP1EAFDZiXg-kVrZjffgSfLFCKU7BZqXOQj8oDZcz8odg=@pm.me> Message-ID: <d4ccb139-469c-b9db-7666-943ed8143b63@gmail.com> On 2/2/25 19:35, Alex Kleider via Tutor wrote: > How to import a module from a src directory for testing > in a test program found in a sister test directory? > > Using Debian Linux... > Here's my project's directory structure: > > TopLevel > ??? __init__.py > ??? src > ??? ??? __init__.py > ??? ??? myprogram.py > ??? tests > ??? __init__.py > ??? test_myprogram.py > > ... and content of relevant files: > > $ cat src/myprogram.py > #!/usr/bin/env python3 > # File: utils/myprogram.py > def print_greeting(): > greeting = "Helo world" > print(greeting) > return greeting > if __name__ == "__main__": > print_greeting() > > $ cat tests/test_myprogram.py > #!/usr/bin/env python3 > # File: tests/test_myprogram.py > from .. src import myprogram > > ... then attempting to run the test: > > $ ./tests/test_myprogram.py > Traceback (most recent call last): > File "/home/alex/Projects/TopLevel/./tests/test_myprogram.py", line 5, in <module> > from ..src import myprogram > ImportError: attempted relative import with no known parent package > > Any help as to how this can be fixed would be most welcome! > Cheers, > Alex Kleider Hey Alex! I apologize for not responding sooner, my mailer has been acting up and I just got this a few minutes ago. You can mangle sys.path to have it look for things, but the consensus is not to do that. My solution has been to use unittest, and to have whatever modules I'm writing tests for to be in the same directory as my tests directory: TopLevel ??? myprogram.py ??? tests ??? __init__.py ??? test_myprogram.py Note that a lot of people like PyTest, and it's pretty good, too. Leam Linux Software Engineer (reuel.net/career) Scribe: The Domici War (domiciwar.net) Coding Ne'er-do-well (github.com/LeamHall) Between "can" and "can't" is a gap of "I don't know", a place of discovery. For the passionate, much of "can't" falls into "yet". -- lh Practice allows options and foresight. -- lh