https://github.com/aidinhamedi/python-check-arg

The check_arg function is a handy Python code snippet that checks if a specific argument exists in a list of arguments. It's a reusable piece of code that you can easily integrate into your projects.

https://github.com/aidinhamedi/python-check-arg

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.5%) to scientific vocabulary

Keywords

argv argv-parser cli functional python python-3 python3 snippets user-interface
Last synced: 6 months ago · JSON representation

Repository

The check_arg function is a handy Python code snippet that checks if a specific argument exists in a list of arguments. It's a reusable piece of code that you can easily integrate into your projects.

Basic Info
  • Host: GitHub
  • Owner: AidinHamedi
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 10.7 KB
Statistics
  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
argv argv-parser cli functional python python-3 python3 snippets user-interface
Created over 2 years ago · Last pushed over 2 years ago
Metadata Files
Readme

README.md

Python-check-arg

The check_arg function is a handy Python code snippet that checks if a specific argument exists in a list of arguments. It's a reusable piece of code that you can easily integrate into your projects.

Function Signature

python def check_arg(arg_list: list, arg_str: str, return_arg: bool = False, bool_OUTPUT_ONLY: bool = False):

Parameters

  • arg_list (list): A list of arguments.
  • arg_str (str): The argument to check for.
  • return_arg (bool, optional): If True, returns the string after the argument if it exists. Defaults to False.
  • bool_OUTPUT_ONLY (bool, optional): If True, only boolean values are returned. If False, specific error codes are returned in case of errors. Defaults to False.

Returns

  • bool/str: Returns True if the argument exists and return_arg is False. Returns the string after the argument if return_arg is True and the argument exists. Returns specific error codes in case of errors, unless bool_OUTPUT_ONLY is True.

Error Codes

  • '![IER:01]': Returned when the provided argument list is empty or contains only 'none' or ''.
  • '![IER:02]': Returned when the argument to check for is an empty string.
  • '![IER:03]': Returned when the argument is found in the argument list, but there is no string after the argument and return_arg is set to True.
  • '![IER:04]': Returned when the argument is not found in the argument list.

Note: If the bool_OUTPUT_ONLY parameter is set to True, the function will return False instead of these error codes.

Usage Examples

```python

Example 1: Check if '-v' exists in the argument list

args = ['-v', '-f', 'file.txt'] print(check_arg(args, 'v')) # Returns: True

Example 2: Get the string after '-z' in the argument list

args = ['-v', '-f', '-z12'] print(checkarg(args, 'z', returnarg=True)) # Returns: '12'

Example 3: Check for an argument that doesn't exist in the list

args = ['-v', '-f', 'file.txt'] print(checkarg(args, 'x')) # Returns: '![IER:04]' or False if boolOUTPUT_ONLY is True ```

Feel free to copy this code snippet and use it in your projects. If you find any issues or have any suggestions for improvements, please open an issue or submit a pull request.

Owner

  • Name: Aidin
  • Login: AidinHamedi
  • Kind: user

Segmentation fault

GitHub Events

Total
Last Year

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 8
  • Total Committers: 1
  • Avg Commits per committer: 8.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Aydin 1****i 8

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels