by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • May 14 22:38
    @bjorno43 banned @minitechtips_twitter
  • May 14 22:37
    @bjorno43 banned @real-action
  • Feb 01 00:26
    @bjorno43 banned @Ndoua
  • Jan 07 03:07
    @bjorno43 banned @doctor-sam
  • Jun 20 2019 21:19
    @bjorno43 banned @shenerd140
  • May 10 2019 09:13
    @bjorno43 banned @zhaokunhaoa
  • Apr 27 2019 19:46
    @mstellaluna banned @zhonghuacx
  • Apr 25 2019 17:13
    @mstellaluna banned @cmal
  • Jan 08 2019 22:04
    @mstellaluna banned @dertiuss323
  • Jan 07 2019 15:43
    User @mstellaluna unbanned @oudarjya718
  • Jan 06 2019 15:14
    @mstellaluna banned @oudarjya718
  • Dec 15 2018 23:38
    @mstellaluna banned @Julianna7x_gitlab
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 22:59
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:13
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 27 2018 19:07
    User @mstellaluna unbanned @JomoPipi
  • Aug 27 2018 06:17
    @mstellaluna banned @JomoPipi
escteban
@escteban
does Python community have something similar to npm to get modules ?
Andrew
@sheerluck
@escteban pip
escteban
@escteban
thanks
Francisco Albert Albusac
@tatitati

HI people, I'm stuck with a very simple thing. I wrote an script:
This is the ridiculous content of my default_args_module.py

default_args = {
   "whatever": "something"
}

Then, with Airflow I'm trying to use this script:

from default_args_module import default_args

but I keep having:

from default_args_module import default_args
ModuleNotFoundError: No module named 'default_args_module'
is weird because if I try to load that module on my own, then I can. PYTHONPATH find it with no problem. However, from Airflow it cannot. And the user is the same (I printied it from Airflow)
Andrew
@sheerluck
@tatitati if you want some dict inside Airflow, do not import it as module, read it as json file:
{
 "default_args": {"whatever": "something"}
}
Francisco Albert Albusac
@tatitati
ou....im trying, thanks for the hint @sheerluck
Francisco Albert Albusac
@tatitati
so I shouldnt use this?: from default_args_module import default_args
Andrew
@sheerluck
no
Francisco Albert Albusac
@tatitati
ok, and if i have a callback like this?:
def failed_task_slack_notification():
        ..<body function>....


{
    'owner': 'whatever',
    'on_failure_callback': failed_task_slack_notification
}
because this is not a simple json..
Andrew
@sheerluck

put your callbacks in a dict, and then read only a KEY from json:

{
'on_failure_callback': "FAILED_TASK_KEY"
}

and somewhere else in code, where you need a not a simple json you just

{
  'on_failure_callback':  mydict[my_conf["on_failure_callback"]]
}
I guess you can find a place for code of callbacks.
without importing that code as a module
Francisco Albert Albusac
@tatitati
ok....i will try it
thanks @sheerluck
Francisco Albert Albusac
@tatitati

well, I tried something much more basic, just
In my_module.py I have

def sayHi():
    print("whatever")

Then In my_dag.py I have

import my_module
my_module.sayHi()

with DAG(.......
     .....

But still I have:
ModuleNotFoundError: No module named my_module

I think the module should be found...but is not happening
Andrew
@sheerluck
I think you should abandon whole idea of importing you code as modules unless you can find an example of such approach in Airflow docs
and if there is no way you can implement your task without import my_module -- you should package you module properly and install it in virtual env with python setup.py install
Francisco Albert Albusac
@tatitati
yeah
thanks @sheerluck :D
I appreciate all your help, we tried :D
bosgithub
@bosgithub
image.png
guys i m scraping yelp, i want to print 10 different reviews from this one link site but its printing the same review 10 times..which part should i fix
vjanz
@vjanz
guys do u prefer pipenv or poetry
Andrew
@sheerluck
@vjanz I don't like how poetry pollutes .poetry/lib/poetry/_vendor with py2.7 and py3.5 and py3.6 and py3.7 when it knows I use only py3.8. btw py2.7 is EOL
Andrew
@sheerluck
@vjanz I don't like how Poetry could not find a pyproject.toml
so yeah I prefer pip + virtualenvwrapper
Yosi
@yosiasz
@vjanz I prefer pip
learningcode
@learningcode9
Hi, Anyone knows How to use multiple checkboxes in Django forms?
djangoReactGuy
@SanskarSans

can anyone help me at this, please?
its a sock merchant question which I am trying to solve but i am getting answer 0.

https://repl.it/repls/SomberWorthyHypertalk

'''
For example, there are n = 7 socks with colors ar = [1, 2, 1, 2, 1, 3, 2]. There is one pair of color 1 and one of color 2. There are three odd socks left, one of each color. The number of pairs is 2.

Given the number of socks in the pile n and an array of colors of each sock, how many pairs do we have?
'''

def sock_merchant(arr):
  pile_of_socks = {}
  pairs = 0
  for i in range(len(arr)):
    if arr[i] in pile_of_socks:
      pile_of_socks[arr[i]] += 1
      if pile_of_socks[arr[i]] % 2 == 0:
        pairs += 1
      pile_of_socks[arr[i]] = 1
  return pairs
Andrew
@sheerluck
@SanskarSans
def sock_merchant(arr):
  from itertools import groupby
  colors = sorted(arr)
  pairs = 0
  for key, group in groupby(colors):
      pairs += len(list(group))//2
  return pairs
@SanskarSans
def sock_merchant(arr):
  from itertools import groupby
  colors = sorted(arr)
  return sum(len(list(group))//2 
             for key, group in groupby(colors))
djangoReactGuy
@SanskarSans
Thank you @sheerluck for your help.
Can i know advantage of using itertools over the above way?
Andrew
@sheerluck
less to type
itertools are fun.
djangoReactGuy
@SanskarSans
the code is very less. Also a new concept for me. I will look at itertools now.
do you have any idea why on my code i just get the result 0?
Andrew
@sheerluck
no
use pudb to step-by-step debug
import pudb; pu.db
djangoReactGuy
@SanskarSans
thank you.
Joseph Gachau
@josephgachau_gitlab
Where can i learn Python and get certification at FCC
niksh2511
@niksh2511
hello :)