關鍵字library、part、part of和import、export的作用

本文详细解析了Dart语言中库的导入与拆分机制,包括import、library、export、part与partof的使用场景及限制条件,阐述了如何在不同文件间共享代码,以及库与部分之间的作用域关系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import

toolUtil.dart;

import 'dart:math';
import 'lib/student/student.dart' as Student

使用的情景:

儅需要使用一個庫時,通過import導入一個庫,import 所用庫的路徑(string)
儅使用的庫名相同時,可以使用關鍵字as來定義一個自定義庫名

限制:

toolUtil.dart 與 math.dart、student,dart的作用於空間並不相互公用,要想在toolUtil.dart使用math.dart的方法必須通過math.dart的類來調用

library

library person 

library定義了庫名,相當于C#中的命名空間的概念

export

library math;

export 'random.dart';

使用情景

儅math庫被import使用時,math庫就會通過export將random.dart導出到使用math庫的頁面中(相當于頁面自動導入了random.dart的庫)

part與part of

A類

part "B.dart" 			//指明B是A的part部分

B類

part of 'A.dart'		//指明B是屬於A的part

part 與 part of是主體與部分的關係,A類與B類公用一個作用於空間,兩者的成員函數可以相互調用

參考:

浅析dart中库的导入与拆分

库的引用

代码解析#@title Check if MuJoCo installation was successful from google.colab import files import distutils.util import os import subprocess if subprocess.run('nvidia-smi').returncode: raise RuntimeError( 'Cannot communicate with GPU. ' 'Make sure you are using a GPU Colab runtime. ' 'Go to the Runtime menu and select Choose runtime type.') # Add an ICD config so that glvnd can pick up the Nvidia EGL driver. # This is usually installed as part of an Nvidia driver package, but the Colab # kernel doesn't install its driver via APT, and as a result the ICD is missing. # (https://github.com/NVIDIA/libglvnd/blob/master/src/EGL/icd_enumeration.md) NVIDIA_ICD_CONFIG_PATH = '/usr/share/glvnd/egl_vendor.d/10_nvidia.json' if not os.path.exists(NVIDIA_ICD_CONFIG_PATH): with open(NVIDIA_ICD_CONFIG_PATH, 'w') as f: f.write("""{ "file_format_version" : "1.0.0", "ICD" : { "library_path" : "libEGL_nvidia.so.0" } } """) # Configure MuJoCo to use the EGL rendering backend (requires GPU) print('Setting environment variable to use GPU rendering:') %env MUJOCO_GL=egl try: print('Checking that the installation succeeded:') import mujoco mujoco.MjModel.from_xml_string('') except Exception as e: raise e from RuntimeError( 'Something went wrong during installation. Check the shell output above ' 'for more information.\n' 'If using a hosted Colab runtime, make sure you enable GPU acceleration ' 'by going to the Runtime menu and selecting "Choose runtime type".') print('Installation successful.') # Tell XLA to use Triton GEMM, this improves steps/sec by ~30% on some GPUs xla_flags = os.environ.get('XLA_FLAGS', '') xla_flags += ' --xla_gpu_triton_gemm_any=True' os.environ['XLA_FLAGS'] = xla_flags
最新发布
07-21
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值